Thymeleaf使用&语法
@ConfigurationProperties(prefix = "spring.thymeleaf")
public class ThymeleafProperties {
private static final Charset DEFAULT_ENCODING = StandardCharsets.UTF_8;
public static final String DEFAULT_PREFIX = "classpath:/templates/";
public static final String DEFAULT_SUFFIX = ".html";
只要我们把HTML页面放在classpath:/templates/,thymeleaf就能自动渲染;
使用:
1.导入thymeleaf的名称空间
<html lang="en" xmlns:th="http://www.thymeleaf.org">
2.使用thymeleaf语法
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>成功!</h1>
<div th:text="${hello}">这是显示欢迎信息</div>
</body>
</html>
语法规则
1)th:text;改变当前元素里面的文本内容;
th:任意html属性;来替换原生属性的值;