欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Thymeleaf在html中的输出

程序员文章站 2022-03-22 21:21:47
...
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>
  点击事件,渲染结果onclick="edit('23')"
  <td><a th:onclick="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>
相关标签: thymeleaf