博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
springboot(九)添加jsp支持
阅读量:4299 次
发布时间:2019-05-27

本文共 1486 字,大约阅读时间需要 4 分钟。

1、添加jar包

org.springframework.boot
spring-boot-starter-tomcat
provided
org.apache.tomcat.embed
tomcat-embed-jasper
provided
javax.servlet
jstl
1.2
jsp不能用Application.java的main方法启动,只能用Tomcat启动,并且要打war包,所以修改打包方式为war:<packaging>war</packaging>

2、在src/main/下创建webapp文件夹,在webapp文件夹下创建WEB-INF文件夹,如图:

3、在DemoApplication里继承SpringBootServletInitializer,并添加@ServletComponentScan

package com.demo;import org.mybatis.spring.annotation.MapperScan;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.context.properties.ConfigurationProperties;import org.springframework.boot.web.servlet.ServletComponentScan;import org.springframework.boot.web.support.SpringBootServletInitializer;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@SpringBootApplication@RestController@ServletComponentScanpublic class DemoApplication extends SpringBootServletInitializer{	@RequestMapping("/")	public String home(){		return "hello world";	}	public static void main(String[] args) {		SpringApplication.run(DemoApplication.class, args);	}}

以上就完成了。在controller里添加跳转测试

@RequestMapping("/turnJsp")    public String turnJsp(){        return "login/login";    }

访问结果如图:

你可能感兴趣的文章
Docker(二) 基础命令
查看>>
Docker(三) 构建镜像
查看>>
Spring 全家桶注解一览
查看>>
JDK1.8-Stream API使用
查看>>
cant connect to local MySQL server through socket /tmp/mysql.sock (2)
查看>>
vue中的状态管理 vuex store
查看>>
Maven之阿里云镜像仓库配置
查看>>
Maven:mirror和repository 区别
查看>>
微服务网关 Spring Cloud Gateway
查看>>
SpringCloud Feign的使用方式(一)
查看>>
SpringCloud Feign的使用方式(二)
查看>>
关于Vue-cli+ElementUI项目 打包时排除Vue和ElementUI
查看>>
Vue 路由懒加载根据根路由合并chunk块
查看>>
vue中 不更新视图 四种解决方法
查看>>
MySQL 查看执行计划
查看>>
OpenGL ES 3.0(四)图元、VBO、VAO
查看>>
OpenGL ES 3.0(五)纹理
查看>>
OpenGL ES 3.0(八)实现带水印的相机预览功能
查看>>
OpenGL ES 3.0(九)实现美颜相机功能
查看>>
FFmpeg 的介绍与使用
查看>>