Thealeaf标签的使用
参看网址为:https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#iteration-basics
1.获取服务器的传递的一个数组,使用 th:each
<tr th:each="a:$(list)">
<td th:text="${a.id}"></td>
<td th:text="${a.title}"></td>
</tr>
说明:a:$(list) 其中:$(list)表示前台传递到页面的list数组;a表示使用别名,可以a.属性名调用相应的属性值
2.获取服务器的传递的一个对象,使用 th:text
<tr>
<td th:text="user.id"></td>
</tr>
说明:user.id表示获取服务器传递到页面user对象中的id值
3.调用点击事件,使用 th:onclick
<button th:onclick=('but()')>
</button>
说明:th:onclick=('but()')表示点击之后触发javaScript里面的but()事件
4.把一个页面用另外一个页面中的布局进行替换,使用 th:onclick(参看文档中layout属性中查找)
<div th:replace="model :: form"></div>
<div th:insert="model :: form"></div>
说明:th:replace="model :: form"replace表示替换整个div,model表示你的html页面,form表示html页面中的form表单;th:insert表示向div中进行插入数据;th:include和insert方法相似
5.向javaScript传递一个参数,使用[ [ ] ]
<button th:onclick="getById([[${a.id}]])">update</button>
说明:getById([[${a.id}]])表示向javaScript中getById方法中传递一个id的值
6.javaScript获取页面传递的参数
<script th:inline="javascript">
var user=[[$("user")]];
</script>
说明: th:inline="javascript"表示定义javaScript标签是使用Thymeleaf里面的标签,var user=[[$("user")]];表示获取服务器向javaScript里面传递user对象值

浙公网安备 33010602011771号