1. 配置 application.properties 文件
-
# 配置视图文件所在位置;
-
spring.mvc.view.prefix=/WEB-INF/views/
-
# 配置视图文件后缀名;
-
spring.mvc.view.suffix=.jsp
2. 添加 maven 依赖(此处仅列出支持 JSP 所需依赖)
-
<!-- 添加 tomcat 的支持 -->
-
<dependency>
-
<groupId>org.springframework.boot</groupId>
-
<artifactId>spring-boot-starter-tomcat</artifactId>
-
<scope>provided</scope>
-
</dependency>
-
<dependency>
-
<groupId>org.apache.tomcat.embed</groupId>
-
<artifactId>tomcat-embed-jasper</artifactId>
-
<scope>provided</scope>
-
</dependency>
-
<!-- servlet 依赖 -->
-
<dependency>
-
<groupId>javax.servlet</groupId>
-
<artifactId>javax.servlet-api</artifactId>
-
<scope>provided</scope>
-
</dependency>
-
<!-- 添加 JSTL 支持 -->
-
<dependency>
-
<groupId>javax.servlet</groupId>
-
<artifactId>jstl</artifactId>
-
</dependency>
3. Controller 方法
-
@RequestMapping("/myTest")
-
public String myTest() {
-
// 跳转到 /WEB-INF/views/hello 下的 myTest.jsp 文件;
-
return "/hello/myTest";
-
}