一,引入依赖jar包,创建项目一定要为war类型
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.22.RELEASE</version>
</parent>
<dependencies>
<!-- SpringBoot 核心组件 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
</dependencies>
二,配置文件
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
三,controller类
@Controller
public class IndexController {
@RequestMapping("/index")
public String index() {
return "index";
}
}
四,启动类,若controller类不在一个包里,加入扫描@ComponentScan
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(AppJsp.class, args);
}
}