栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

【Thymeleaf】获取Thymeleaf的当前日期

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【Thymeleaf】获取Thymeleaf的当前日期

前言

直接使用Thymeleaf获取当前时间,并进行格式化

实施
  1. 添加pom文件
  
     org.springframework.boot
      spring-boot-starter-thymeleaf
  
  
      org.thymeleaf.extras
      thymeleaf-extras-java8time
  
  1. Thymeleaf格式如下
th:text="${#dates.format(#dates.createNow(), 'yyyy-MM-dd HH:mm')}"
  1. 实例:



    
    巡检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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/679014.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号