thymeleaf的jsp日期写法

本文介绍了如何在Spring Boot项目中集成Thymeleaf模板引擎,通过添加Maven依赖并引入Thymeleaf的XML命名空间,实现动态数据展示,如日期格式化和条件判断。示例中展示了遍历列表、根据状态显示不同文本以及构建可点击的审核链接等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

thymeleaf的写法和EL表达式的写法是有些类似的,总的说thymeleaf的写法更好:
在这里插入图片描述
官网doc:https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#simple-conditionals-if-and-unless
首先加入模板引擎的maven配置:

 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

在页面引入thymeleaf:

xmlns:th="http://www.thymeleaf.org"
 <td th:text="${#dates.format(i.startdate,'yyyy-MM-dd')}"></td>
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>text</title>
</head>
<body>
 <table>
<tr th:each="i:${list}">
            <td th:text="${i.id}"></td>
            <td th:text="${i.projectname}"></td>
            <td th:text="${#dates.format(i.startdate,'yyyy-MM-dd')}"></td>
            <td th:text="${#dates.format(i.enddate,'yyyy-MM-dd')}">
            </td>
            <td th:if="${i.status eq 1}">已申报</td>
            <td th:if="${i.status eq 2}">审核中</td>
            <td th:if="${i.status eq 3}">已审核</td>

            <td th:if="${i.status ne 3}">
                <a th:href="@{'getOne/'+${i.id}}">审核</a>
            </td>
            <td th:if="${i.status eq 3}">已审核</td>
        </tr>
            </table>
</div>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天元白手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值