- Springboot的默认视图支持是Thymeleaf,想要使用JSP视图需要添加以下依赖:
<!-- servlet依赖 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- 内置tomcat对jsp的支持--> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> </dependency> |
- 在main路径下新建webapp/META-INF/resources/jsp用于存放JSP视图
- 指定web资源路径
- JSP视图在Spring Boot中需要被指定在webapp/META-INF/resources目录下
<build> <resources> <resource> <directory>src/main/webapp</directory> <targetPath>META-INF/resources</targetPath> <includes> <include>*.*</include> </includes> </resource>
<resource> <directory>src/main/resources</directory> <includes> <include>**/*.*</include> </includes> </resource> </resources> </build> |
- 在全局配置文件 application.properties 中配置视图解析器前缀和后缀
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp