thymeleaf在页面中输出格式th:field,其中filed是各标签中的属性
1、在table中遍历List
<tr th:each="item,itemStat : ${list}"> //输出序列号 <td th:text="${itemStat.count}">序号</td> //输出变量值 <td th:text="${item.code}">代码</td> //点击事件,渲染结果οnclick="edit('23')" <td><a th:οnclick="edit+'(' +'\''+${item.code}+'\'' +')'">>编辑</a></td>
2、if-else可以使用switch-case来实现
<div th:switch="${editable}"> <div th:case="true">true</div> <div th:case="false">false</div> </div>
3、js中赋值
<script th:inline="javascript"> var msg = [[${msg}]]; </script>
注:${}中的变量都是从后台传入的,在SpringMVC中:
ModelAndView mav = new ModelAndView("/pagepath");
mav.addObject("msg", "error");
4、thymeleaf中输出html标签 使用th:utext
<p th:utext="#{home.welcome}">Welcome to our grocery store!</p> //效果: <p>Welcome to our <b>fantastic</b> grocery store!</p>
————————————————
版权声明:本文为CSDN博主「houjguang」的原创文章