SpringBoot返回HTML视图
废话不多说,直接进入主题,SpringBoot必须要依赖视图引擎才能返回视图。
引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
Controller
@RestController
public class MyController {
@GetMapping("/index")
public ModelAndView index(){
return new ModelAndView("index");
}
}
配置文件
thymeleaf:
prefix: classpath:/templates/