直接使用Thymeleaf获取当前时间,并进行格式化
实施- 添加pom文件
org.springframework.boot spring-boot-starter-thymeleaf org.thymeleaf.extras thymeleaf-extras-java8time
- Thymeleaf格式如下
th:text="${#dates.format(#dates.createNow(), 'yyyy-MM-dd HH:mm')}"
- 实例:
巡检ES索引模板shard个数不合理
巡检时间:, 巡检ES索引模板shard个数不合理处理详情如下!
------------------------------
| 索引模式名称: | 修改索引模板结果 | 修改索引模板状态 |
|---|---|---|
报错信息:
org.springframework.expression.spel.SpelevaluationException: EL1004E: Method call: Method format(java.time.LocalDateTime,java.lang.String) cannot be found on type org.thymeleaf.expression.Dates
at org.springframework.expression.spel.ast.MethodReference.findAccessorForMethod(MethodReference.java:226) ~[spring-expression-5.3.12.jar:5.3.12]
at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:135) ~[spring-expression-5.3.12.jar:5.3.12]
at org.springframework.expression.spel.ast.MethodReference.access$000(MethodReference.java:55) ~[spring-expression-5.3.12.jar:5.3.12]
at org.springframework.expression.spel.ast.MethodReference$MethodValueRef.getValue(MethodReference.java:387) ~[spring-expression-5.3.12.jar:5.3.12]
at org.springframework.expression.spel.ast.Compoundexpression.getValueInternal(Compoundexpression.java:92) ~[spring-expression-5.3.12.jar:5.3.12]
at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:112) ~[spring-expression-5.3.12.jar:5.3.12]
at org.springframework.expression.spel.standard.Spelexpression.getValue(Spelexpression.java:337) ~[spring-expression-5.3.12.jar:5.3.12]
at org.thymeleaf.spring5.expression.SPELVariableexpressionevaluator.evaluate(SPELVariableexpressionevaluator.java:265) ~[thymeleaf-spring5-3.0.12.RELEASE.jar:3.0.12.RELEASE]
at org.thymeleaf.standard.expression.Variableexpression.executeVariableexpression(Variableexpression.java:166) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]
at org.thymeleaf.standard.expression.Simpleexpression.executeSimple(Simpleexpression.java:66) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]
at org.thymeleaf.standard.expression.expression.execute(expression.java:109) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]
at org.thymeleaf.standard.expression.expression.execute(expression.java:138) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]
at org.thymeleaf.standard.processor.AbstractStandardexpressionAttributeTagProcessor.doProcess(AbstractStandardexpressionAttributeTagProcessor.java:144) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]
解决方案:
查找相关资料,发现thymeleaf对于此类报错,增加了一个增强包,maven工程中需要在pom中引入如下包:
org.thymeleaf.extras thymeleaf-extras-java8time



