springboot中controller返回视图的路径
1.不使用thymeleaf模板引擎的时候
默认根路径为static
@RequestMapping("/thymeleaf/haha")
public String toHtml(){
System.out.println("进入");
return "/haha.html"; //找到resources下的static下的haha.html
}
可以配置前后缀
spring:
mvc:
view:
prefix: /
suffix: .html
@RequestMapping("/thymeleaf/haha")
public String toHtml(){
System.out.println("进入");
return "haha"; //找到resources下的static下的haha.html
}
2.使用thymeleaf模板后
添加thymeleaf依赖后,默认根路径改为templates
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
@RequestMapping("/thymeleaf/haha")
public String toHtml(){
System.out.println("进入");
return "haha"; //找到resources下的templates下的haha.html
}