@JsonFormat对日期进行格式化后,在thymeleaf渲染页面中无效的问题

发布时间 2023-09-21 09:34:36作者: xashould

问题:对于使用了 @JsonFormat对日期进行格式化后,在thymeleaf渲染的页面中显示不是 @JsonFormat 格式化后的数据。

原因:因为 thymeleaf 中有自己的日期格式化。

解决:通过使用 thymeleaf 中的日期格式化在页面中进行日期格式化。即通过 ${#dates.format(日期参数,'yyyy-MM-dd')}

<span th:text="${#dates.format(blogtro.bDate,'yyyy-MM-dd')}"></span>