文章目录
模板布局
th:fragment
th:insert
th:replace
th:remove
-
th:fragment=“body” 模板布局:指会经常被别人引用的一部分,为他打上标签,以便引用
<div th:fragment="copy"> © 2011 The Good Thymes Virtual Grocery </div>
-
th:insert=“commons/commons::body” 在指定部分引用模板布局
-
th:replace=“commons/commons::body” 在指定部分引用模板布局
<body> ... <div th:insert="~{footer :: copy}"></div> ... </body>
-
th:remove=“tag” 移除当前标签或子标签
<!--tag:删除自己,但不删除所有子项--> <div class="hint" th:remove="tag"> <p>tag<span> $</span></p> </div>
表单提交
th:action
- th:action="@{/aBcd/eee}" 表单提交地址,相当于action
解析数据
th:object
th:field
th:value
th:text
th:utext
- th:object="${xxForm}" 解析后端传前端的数据使用
- th:field="*{name}"
<div th:object="${userInfoForm}"> <p>name: <span th:text="*{name}">XXXX</span>.</p> <input th:field="*{name}"/> </div>
- th:value="${intermediary.piCode}" 解析后端传前端的数据使用
<input th:value="${userInfoForm.name}"/>
- th:field="*{name}" 等同于th:name和th:value,而 th:value="${intermediary.piCode}" 只为value
th:field="*{name}" 在前面要有使用th:object才可以使用
- th:text="${message}" 文本替换
- th:utext="${message}" 支持html的文本替换
当前日期:<span th:text="${dt}"></span>超出平均值 <span th:text="${ratioPercent}+'%'"></span>
emmm
-
th:checked=“true” 复选框选中
<input type="checkbox" name="typeCustomer" value="1" th:checked="*{customerType} eq '1'"/>
-
th:if="${code}"
<span th:if="*{code != null}" th:text="*{code}"></span> <!--if属性结果为 true,模板会进行显示--> <p th:if="true">th:if="true"</p> <!--if属性结果为 false,模板不会进行显示--> <p th:if="false">th:if="false"</p>
-
th:each=“intermediary:${intermediaryList}” 遍历
<tr th:each="user : ${userList}"> <td th:text="${user.name}">xxx</td> </tr>
th:block
- 块标签(空标签),标签本身不显示
<th:block th:if='${1!=1}'> <button class="btn btn-default" data-toggle="modal" data-target="#myModal"> <i class="fa fa-plus"></i> 新增2不显示 </button> </th:block>
- th:classappend=“big-big” 在不改变标签内class属性的前提下,添加某class样式
<div class="big-box" th:classappend="${captchaEnabled == false} ? 'm-t': ''">111</div>