Html 在thymeleaf中的本地日期时间内的属性
LocalDateTime作为application.property 我的application.properties如下所示:Html 在thymeleaf中的本地日期时间内的属性,html,spring,thymeleaf,Html,Spring,Thymeleaf,LocalDateTime作为application.property 我的application.properties如下所示: <p th:text="${#temporals.format(localDateTime, __${''''+@environment.getProperty('date.format')+''''}__)}"> date.format='dd-MM-yyyy' 如何用我的财产替换“dd-MM-yyyy” 您可以从@environment获取属性
<p th:text="${#temporals.format(localDateTime, __${''''+@environment.getProperty('date.format')+''''}__)}">
date.format='dd-MM-yyyy'
如何用我的财产替换“dd-MM-yyyy”
@environment
获取属性
@environment.getProperty('date.format')
\uuu
因此,正如您所看到的,从控制器传递格式要容易得多)您是否尝试过
”
)
这是什么@environment?我需要在早些时候指定它?您说您已经在application.properties中声明了它,因此@environment将访问此文件,但它没有(很遗憾):(数字2对我有用,因为我将属性设置为:date.time.format='dd-MM-yyyyy HH:MM',而不是date.time.format=dd-MM-yyyy HH:MM):mm@degath是的,这取决于你的属性文件。如果你有引号,你可以跳过3-d步骤。你的答案非常可靠。我会考虑控制器的pass格式,但现在它工作了,所以ofc我会接受你的答案。谢谢:)
<p th:text="${#temporals.format(localDateTime, __${@environment.getProperty('date.format')}__)}">
<p th:text="${#temporals.format(localDateTime, __${''''+@environment.getProperty('date.format')+''''}__)}">