首页 > 其他 > 详细

thymeleaf学习笔记

时间:2019-10-09 23:34:49      阅读:116      评论:0      收藏:0      [点我收藏+]

1.导入thymeleaf名称空间

<html lang="zh-Hans" xmlns:th="http://www.thymeleaf.org">

2.thymeleaf语法

2.1 循环遍历 th:each

<div th:each="article,ArticleList:${articleList}"></div>

2.2 三元运算

解释:如果article.getArticleCover得到的值不是‘‘ 则该div应用cover这个class属性否则noimg

<div th:class="${article.getArticleCover()!=‘‘}?cover:noimg">

2.3 时间格式化

<div class="stat" th:text="${#dates.format(article.getUpdateDate(), ‘yyyy-MM-dd HH:mm:ss‘)}">

 

示例

<div class="article" th:each="article,ArticleBean:${articleList}">
                    <a th:href="‘http://localhost:8080/p/‘+${article.getArticleId()}+‘.html‘" target="_blank">
                        <div class="row">
                        <div class="title" th:text="${article.getArticleTitle()}">

                        </div>
                        <div th:class="${article.getArticleCover()!=‘‘}?cover:noimg">
                            <img th:src="${article.getArticleCover()}" th:class="${article.getArticleCover()!=‘‘}?img:noimg"/>
                        </div>
                        <div class="sketch" th:text="${article.getArticleSketch()}">

                        </div>
                        <div class="other">
                            <div class="icon">
                                <span class="glyphicon glyphicon-user" aria-hidden="true"></span>
                            </div>
                            <div class="stat" th:text="${article.getArticleAuthor()}">

                            </div>
                            <div class="icon">
                                <span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span>
                            </div>
                            <div class="stat" th:text="${article.getArticleReadNum()}">

                            </div>
                            <div class="icon">
                                <span class="glyphicon glyphicon-tag" aria-hidden="true"></span>
                            </div>
                            <div class="stat next" th:text="${article.getArticleLabel()}">

                            </div>
                            <div class="icon">
                                <span class="glyphicon glyphicon-time" aria-hidden="true"></span>
                            </div>
                            <div class="stat" th:text="${#dates.format(article.getUpdateDate(), ‘yyyy-MM-dd HH:mm:ss‘)}">

                            </div>
                        </div>
                        </div>
                    </a>
                </div>

thymeleaf学习笔记

原文:https://www.cnblogs.com/ushowtime/p/11644861.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!