spring boot 学习笔记(二) 构建web支持jsp

时间:2023-12-28 13:52:14

一、必须将项目打包成war包

<packaging>war</packaging>

二、pom.xml加入依赖包

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--jsp支持-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<scope>compile</scope>
</dependency>

三、application.properties

spring.mvc.view.prefix=/WEB-INF/jsps/
spring.mvc.view.suffix=.jsp
spring.thymeleaf.cache=false    //这个是关闭thymeleaf缓存
spring.thymeleaf.enabled = false  //关闭thymeleaf模板

四、在项目中src/main/下建立 webapp/WEB-INF/jsps/

spring boot 学习笔记(二) 构建web支持jsp

五、controller

@Controller
public class TestController {
  @RequestMapping("jsps")
public ModelAndView testJsp(){
return new ModelAndView("index");
}
}

六、访问 http://localhost:8080/jsps ok。