首先在application.yml文件或application.properties里添加配置
spring: mvc: view: prefix: /WEB-INF/jsp/ suffix: .jsp接着在pom.xml添加依赖包
<dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <scope>provided</scope> </dependency>最后在控制层添加一小段代码(记得给控制层添加@Controller)
//打开所有jsp页面 @RequestMapping("/{view}") public String html(@PathVariable("view")String view){ return view; }//其中view就是你要打开的视图哦 打开html页面首先步骤jsp差不多,一样在application.yml文件添加配置
注意别漏了classpath:,会报错的
接着在pom.xml添加模板
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>最后一步跟都一样
//打开所有html页面 @RequestMapping("/{view}") public String html(@PathVariable("view")String view){ return view; }//其中view就是你要打开的视图哦然后启动你的项目会默认打开index.html页面哦!
最后这是我的目录结构
注:第一次发表