Spring 百里香。如何比较日期是来自未来还是过去?
我想检查Employee.dateOfTermination中的日期是否在日期“now”之后。不幸的是,在运行以下代码后,我没有得到任何数据:Spring 百里香。如何比较日期是来自未来还是过去?,spring,thymeleaf,Spring,Thymeleaf,我想检查Employee.dateOfTermination中的日期是否在日期“now”之后。不幸的是,在运行以下代码后,我没有得到任何数据: <td> <div th:switch="${employee.dateOfTermination}"> <span th:case="'< now'">CASE 1</span>
<td> <div th:switch="${employee.dateOfTermination}">
<span th:case="'< now'">CASE 1</span>
<span th:case="'> now'" th:text="${#dates.format(employee.dateOfTermination, 'dd-MM-yyyy')}">CASE 2</span></div></td>
案例1
案例2
问题来了,thymeleaf的语法对我来说似乎不可靠,令人厌恶。我尝试了th:if,并解析了一个int。我会这样做:
<span th:if="${employee.dateOfTermination.before(#dates.createNow())}">Case 1</span>
<span th:if="${employee.dateOfTermination.after(#dates.createNow())}">Case 2</span>
案例1
案例2
或者,如果你喜欢这个开关:
<div th:switch="${employee.dateOfTermination.before(#dates.createNow())}">
<span th:case="true">Case 1</span>
<span th:case="false">Case 2</span>
</div>
案例1
案例2
我会这样做:
<span th:if="${employee.dateOfTermination.before(#dates.createNow())}">Case 1</span>
<span th:if="${employee.dateOfTermination.after(#dates.createNow())}">Case 2</span>
案例1
案例2
或者,如果你喜欢这个开关:
<div th:switch="${employee.dateOfTermination.before(#dates.createNow())}">
<span th:case="true">Case 1</span>
<span th:case="false">Case 2</span>
</div>
案例1
案例2