2021-02-16-Thymeleaf common syntax

Introducing namespace

<html lang="en" xmlns:th="http://www.thymeleaf.org/">

Take value from domain object

req:<span th:text="${reqKey}"></span><br>
session:<span th:text="${session.sessionKey}"></span><br>
application:<span th:text="${application.applicationKey}"></span><br>
内置对象:<span th:text="${#request.getAttribute('reqKey')}"></span>

Thymeleaf common operations

<base th:href="${#request.getContextPath()+'/'}">

<td th:text="${#dates.format(user.createTime,'yyyy-MM-dd')}"></td>

<input type="hidden" name="id" th:value="%{user.id}" >

<script th:inline="javascript">
    var message = [[${user.username}]];
    var username=[[${#request.getParameter('returnUrl')}]];
    console.log(message);

</script>

th:onclick="|admin_edit('user/getUserById/${user.id}')|"

<p class="miaoshu" th:utext="${goods.ginfo}"></p>

<tr th:each="topic:${page.list}">

<span th:text="${sex ==1?'男':'女'}"></span>

<span th:text="${#numbers.formatDecimal(price,4,3)}"></span>
#numbers.formatDecimal(numbwe,整数位,小数位)。
整数位表示,整数位不足四位,用0补齐

<img th:each="img:${#strings.listSplit(gg.gimage,'|')}" th:src="${img}">

Thymeleaf template parser properties

#开启模板缓存(默认值:true)
spring.thymeleaf.cache=true 

#在呈现模板之前,检查模板是否存在
spring.thymeleaf.check-template=true 

#检查模板位置是否正确(默认值:true)
spring.thymeleaf.check-template-location=true

#Content-Type的值(默认值:text/html)
spring.thymeleaf.content-type=text/html
#开启MVC Thymeleaf视图解析(默认值:true)
spring.thymeleaf.enabled=true

#模板编码
spring.thymeleaf.encoding=UTF-8

#要被排除在解析之外的视图名称列表,用逗号分隔
spring.thymeleaf.excluded-view-names=

#要运用于模板之上的模板模式。另见StandardTemplate-ModeHandlers(默认值:HTML5)
spring.thymeleaf.mode=HTML5

#在构建URL时添加到视图名称前的前缀(默认值:classpath:/templates/)
spring.thymeleaf.prefix=classpath:/templates/

#在构建URL时添加到视图名称后的后缀(默认值:.html)
spring.thymeleaf.suffix=.html

#Thymeleaf模板解析器在解析器链中的顺序。默认情况下,它排第一位。顺序从1开始,只有在定义了额外的TemplateResolver Bean时才需要设置这个属性。
spring.thymeleaf.template-resolver-order=

#可解析的视图名称列表,用逗号分隔
spring.thymeleaf.view-names=

Guess you like

Origin blog.csdn.net/qq_41270550/article/details/113793063