1.在application.properties中定义好访问jsp文件的配置
#jsp page
#new springboot version
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
#old springboot version
#spring.view.prefix=/WEB-INF/jsp/
#spring.view.suffix=.jsp
2.在pom.xml中添加访问jsp页面的jar包
<!-- 访问jsp页面所需要的以下依赖包 -->
<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>
3.IndexControl类如下
@Controller
public class IndexControl {
@RequestMapping(value="/index",method = RequestMethod.GET)
public String index() {
return "index";
}
}
4.新建一个index.jsp文件,放到src\main\webapp\WEB-INF\jsp\目录下,没有目录新建即可
5.访问地址如下:
http://127.0.0.1:8080/index 就可以访问对应的index.jsp文件