百里香叶。如何比较日期是未来的还是过去的?

0 spring thymeleaf

我想检查 Employee.dateOfTermination 中的日期是否在日期“现在”之后。不幸的是,运行以下代码后,我没有得到任何数据:

<td> <div th:switch="${employee.dateOfTermination}"> 
                            <span th:case="'&lt; now'">CASE 1</span>
                            <span th:case="'&gt; now'" th:text="${#dates.format(employee.dateOfTermination, 'dd-MM-yyyy')}">CASE 2</span></div></td>
Run Code Online (Sandbox Code Playgroud)

问题来了,thymeleaf 的语法对我来说确实显得不适用而且恶心。我尝试使用 th:if 并解析 int 。

Met*_*ids 5

我会这样做:

<span th:if="${employee.dateOfTermination.before(#dates.createNow())}">Case 1</span>
<span th:if="${employee.dateOfTermination.after(#dates.createNow())}">Case 2</span>
Run Code Online (Sandbox Code Playgroud)

或者,如果您确实喜欢这个开关:

<div th:switch="${employee.dateOfTermination.before(#dates.createNow())}">
    <span th:case="true">Case 1</span>
    <span th:case="false">Case 2</span>
</div>
Run Code Online (Sandbox Code Playgroud)