Thymeleaf

总结部分Springboot使用Thymeleaf渲染html容易出现的问题:

1.<html xmlns:th="http://www.thymeleaf.org">,必须添加xmlns:th="http://www.thymeleaf.org;

2.<span>头条资讯      [[${#dates.format(new java.util.Date().getTime(), 'yyyy-MM-dd')}]] </span>,这是获取当前时间然后进行格式化;

3.<div th:each="vo:${vos}">  

       <li th:text="${vo.get('news').likeCount}"></li>

  这是要进行循环,获取每个值;

4.<img class="content-img" th:src="${vo.get('news').image}"/>,这是显示图片,src前面要加上th: ;

5.<a th:href="@{'/user/'+${vo.get('user').id}}"><img width="32" class="img-circle" th:src="${vo.get('user').headUrl}"/></a>,这是点击图片以后要跳转到其它页面,href前面要加上th:,路径前面加上@符号,另外路径='字符串'+动态参数

6.以下是我判断user是否为null,为null显示注册登录,否则显示user的name。

<div class="top">
<span th:if="${user!=null}">
<li th:text="${user.name}"></li>
</span>
<span th:unless="${user!=null}">
<li><a href="/reglogin">注册/登录</a></li>
</span>
</div>

 7.日期转换:

<p th:text="${#dates.format(commentvo.get('comment').createdDate, 'yyyy-MM-dd HH:mm:ss')}"></p>
原文地址:https://www.cnblogs.com/xp1234/p/11697957.html