1、导入相关依赖     (存在jsp页面下载问题,可能是缺少tomcat-embed-jasper的依赖对jsp的支持)

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--springboot自带的tomcat并没有携带tomcat-embed-jasper的依赖(对jsp的支持的依赖)-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
</dependencies>

 2、配置application.properties文件

spring.mvc.view.prefix=/pages
spring.mvc.view.suffix=.jsp

3、controller层及springboot启动类

@Controller
public class IndexController {
@RequestMapping("/index")
public ModelAndView index(){

ModelAndView mv=new ModelAndView();
mv.setViewName("/index");
return mv;
}
}

 

@SpringBootApplication

public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}

 注:如果没有使用springboot自带的tomcat,使用外部tomcat的

添加依赖依赖:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId> //spring-boot-starter-tomcat里面有tomcat-embed-jasper依赖
<scope>provided</scope>
</dependency>