我偶然发现了和你一样的问题。
不起作用的原因是您需要使用#temporals 而不是#dates。
为此,您需要将 thymeleaf-extras-java8time 依赖项添加到您的项目中:
compile("org.thymeleaf.extras:thymeleaf-extras-java8time:3.0.4.RELEASE")
请记住,Locale 功能是在 2.1.0 版发布之后添加的,因此您必须使用 Thymeleaf 3。添加:
compile("org.thymeleaf:thymeleaf-spring4:3.0.6.RELEASE")
compile("org.thymeleaf:thymeleaf:3.0.6.RELEASE")
compile("nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:2.2.2")
正如@Andreas 指出的,你需要指定整个包名,例如:
<td th:text="${#temporals.format(embargo.fecha, 'dd-MMMM-yyyy', new java.util.Locale('es', 'ES'))}"></td>
还要注意#temporals 不适用于 java.util.Dates,但它们适用于 java.time.LocalDate 和 java.time。本地日期时间
如果您无法将后端更改为使用 java.time.LocalDate,则解决方案是使用静态方法从您 java.util.Date 创建它of(year, month, day) 来自 LocalDate 类。
例如:
T(java.time.LocalDate).of(#dates.year(embargo.fecha), #dates.month(embargo.fecha), #dates.day(embargo.fecha))
把它放在你的例子中,它会变成:
<td th:text="${#temporals.format(T(java.time.LocalDate).of(#dates.year(embargo.fecha), #dates.month(embargo.fecha), #dates.day(embargo.fecha)), 'dd-MMMM-yyyy', new java.util.Locale('es', 'ES'))}"></td>
希望对你有帮助!