thymeleaf学习笔记

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>
posted @ 2019-10-09 22:28  执笔coding  阅读(240)  评论(0编辑  收藏  举报