java-Thymeleaf : how get next date?

标签 java thymeleaf

我想要这样的列表:

<ul>
  <li>2017-01-31</li> <!-- I want today date -->
  <li>2017-02-01</li> <!-- I want tomorrow date -->
  <li>2017-02-02</li> <!-- I want next day date -->
</ul>

现在我只有第一个li:

<ul>
  <li>th:text="${#dates.format(#dates.createToday(), 'yyyy-MM-dd')</li>
</ul>

如何获取下一个日期(例如:#dates.createToday() + "1 day")?

最佳答案

这是 thymeleaf 做得不好的地方......也就是说,如果你在 pom 中包含 common-lang3,你可以让它像这样工作:

POM:

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.5</version>
</dependency>

thymeleaf :

    <ul>
        <li th:each="i: ${#numbers.sequence(0,2)}" th:with="util=${T(org.apache.commons.lang3.time.DateUtils)},date=${util.addDays(#dates.createToday(), i)}" th:text="${#dates.format(date, 'yyyy-MM-dd')}" />
    </ul>

我建议您在 Controller 中添加日期(在 java 中创建它们,这很容易),然后在 thymeleaf 中循环和格式化。

关于java-Thymeleaf : how get next date?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42020634/

相关文章:

java - Spring bean 作用域。单例和原型(prototype)

java - 使用 Hamcrest Matchers 检查 JsonPath 的输出

java - Sencha GXT Grid 小部件 ListStore.getAll() 仅返回部分数据

css - 如何在 jhipster 应用程序中使用 bootstrap 和 thymeleaf

java - thymeleaf (th :action) not working when rendering long html

Spring 和 thymeleaf : changing locale and stay on the current page

java - 遍历列表中的列表并显示在表中

Java - 消息 header 值 : Basic 中的非法字符

java - @Transactional 方法中所做的更改不会反射(reflect)到实体

java - 带有 Thymeleaf 的 Spring Security 的简单示例