spring.thymeleaf.encoding=UTF-8
使用模板响应类型
spring.thymeleaf.servlet.content-type=text/html
默认无法直接访问templates下的页面, 需要设置
以后static下放css与js, templates下放页面
spring.resources.static-locations=classpath:/templates, classpath:/static
引入下面的依赖是为了可以直接访问 html 页面:
spring.resources.static-locations=classpath:/templates, classpath:/static
例如 **不经过控制器** 访问 `resources/templates/hello.html`:如果不配置上面则无法访问。
http://localhost:8080/index.html
[](https://codechina.csdn.net/m0_60958482/java-p7)控制器访问 html 页面
--------------------------------------------------------------------------------
使用 Thymeleaf **模板页面** 默认放在 `resources/templates` 目录中
创建一个 `/resources/templates/hello.html` 页面:
<meta charset="UTF-8">
<title>hello</title>
SpringBoot 集成 Thymeleaf!!!
编写控制器:
@Controller
@RequestMapping("/hello")
public class HelloController {
@GetMapping("/hello")
public String hello() {
System.out.println("hello spring boot!");
return "hello";
}
}
测试访问:
http://localhost:8080/hello/hello
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200621020219341.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzczNDA5NQ==,size_16,color_FFFFFF,t_70)
[](https://codechina.csdn.net/m0_60958482/java-p7)Thymeleaf 基本使用
=======================================================