Young87

当前位置:首页 >个人收藏

thymeleaf 使用手册

thymeleaf 是一个标签语言,类似于c标签,下面实际工作举例,列举常用规则说明:

【1】输入框中显示用户姓名。

姓名:<input type="text" name="name" th:value="${user.name}">

【2】下拉选择月份 :其中monthList为月份数据,th:field为回显数据(这里回显值为query对象中的mid属性)。

<span>月份:</span>
<select name="mid" th:field="${query.mid}">
    <option th:each="each : ${monthList}" th:text="${each.name}"  th:value="${monthList.id}"></option>
</select>

【3】链接

  • 第一个链接为显示用户姓名,点击姓名会自动跳转到用户详情页面,这里后面会携带一个id参数。
  • 第二个为用户点击自己的详情页面,不携带参数(id后台session中获取)。 
<a th:href="@{/user/detail(id=${user.id})}"  th:text="${user.name}"></a>
<a th:href="@{'/system/dis/user/detail'}">个人详情</a>

 【4】判断条件:只有当用户状态为2时,才支持编辑操作。

<a th:unless="${user.status==2}">编辑</a>

【5】循环:展示用户列表 。

<table>
    <tr>
        <th width="20%">姓名</th>
        <th width="10%">年龄</th>
        <th width="70%">地址</th>
    </tr>
    <tr th:each="user:${userList}">
        <td th:text="${user.name}"></td>
        <td th:text="${user.age}"></td>
        <td th:text="${user.address}"></td>
    </tr>
</table>

【6】 页面引用:引用工程system文件夹下的page.html文件。

<div th:replace="system/page"></div>

【7】时间格式化:格式化后台Date类型字段createTime,显示为 yyyy-MM-dd 日期格式。

创建时间:<input type="text" th:value="${#calendars.format(batch.createTime,'yyyy-MM-dd')}">

【8】拼接:用两条竖线包起来,里面可以随意拼接 

<a th:onclick="|deleteById('${user.id}')|">删除</a>

【9】显示html内容(如博客内容显示:需要将博客中的图片、链接等按原排版显示出来)

<div th:utext="${boke.content}"></div>

 

除特别声明,本站所有文章均为原创,如需转载请以超级链接形式注明出处:SmartCat's Blog

上一篇: 数字图像处理 - 灰度级分层 的python实现

下一篇: 欢迎加入 Apache IoTDB !

精华推荐