导入相关依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
ThymeleafProperties 配置类
1.默认编码
2.前缀
3.后缀
相当于视图解析器
package com.kuang.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
//templates在这个目录下的所有页面,只能通过controller来访问,相当于一起的WEB-INF目录
//需要导入模板引擎
//模板引擎是视图解析器,只能通过服务器转发,请求是请求不到的,拼接获取html,静态资源实现的是,路径映射。有优先级。
public class IndexController {
@RequestMapping("/index")
public String index(){
return "/test";
}
}
这是学SpringBoot的必经之路,非常重要!!!(除非你是学前端的)
只改了前端代码点一下这个就可以刷新
@RequestMapping("/index")
public String index(Model model){
model.addAttribute("msg","hello springboot");
return "/test";
}
传值过来了
th:text="${msg}"爆红,但是可以显示,File->Settings->Editor->Inspection 取消“Expression variables validation”的勾选