FreeMarker template error:Can‘t convert the date-like value to string because it isn‘t known if it‘

FreeMarker template error:Can‘t convert the date-like value to string because it isn‘t known if it‘,第1张

FreeMarker template error:Can‘t convert the date-like value to string because it isn‘t known if it‘

FreeMarker template error:
Can't convert the date-like value to string because it isn't known if it's a date (no time part), time or date-time value.
The blamed expression:
==> (time)!''  [in template "strTpl" at line 1, column 3]

----
Tip: Use ?date, ?time, or ?datetime to tell FreeMarker the exact type.
----
Tip: If you need a particular format only once, use ?string(pattern), like ?string('dd.MM.yyyy HH:mm:ss'), to specify which fields to display.
----

----
FTL stack trace ("~" means nesting-related):
    - Failed at: ${(time)!""}  [in template "strTpl" at line 1, column 1]
----

Java stack trace (for programmers):
----
freemarker.core._TemplateModelException: [... Exception message was already printed; see it above ...]
    at freemarker.core._MessageUtil.newCantFormatUnknownTypeDateException(_MessageUtil.java:301)
    at freemarker.core.Environment.getTemplateDateFormat(Environment.java:1660)
    at freemarker.core.Environment.getTemplateDateFormat(Environment.java:1645)
    at freemarker.core.evalUtil.coerceModelToStringOrMarkup(evalUtil.java:380)
    at freemarker.core.evalUtil.coerceModelToStringOrMarkup(evalUtil.java:358)
    at freemarker.core.DollarVariable.calculateInterpolatedStringOrMarkup(DollarVariable.java:100)
    at freemarker.core.DollarVariable.accept(DollarVariable.java:63)
    at freemarker.core.Environment.visit(Environment.java:330)
    at freemarker.core.Environment.process(Environment.java:309)
    at freemarker.template.Template.process(Template.java:384)
    at com.xfs.micro.common.module.utils.tools.FreemarkerTemplateUtil.processFreemarker(FreemarkerTemplateUtil.java:32)
    at com.xfs.micro.log.service.buried.filter.BuriedPointEvidenceFilter.main(BuriedPointEvidenceFilter.java:90)
Caused by: freemarker.core.UnknownDateTypeFormattingUnsupportedException: Can't convert the date-like value to string because it isn't known if it's a date (no time part), time or date-time value.
    at freemarker.core.Environment.getTemplateDateFormat(Environment.java:1722)
    at freemarker.core.Environment.getTemplateDateFormat(Environment.java:1492)
    at freemarker.core.Environment.getTemplateDateFormat(Environment.java:1658)
    ... 10 more

按报错提示信息修改问题:

${requestInfo.requestTime?string('yyyy-MM-dd HH:mm:ss.SSS')}

不可以写成${requestInfo.requestTime?string("yyyy-MM-dd HH:mm:ss.SSS")}否则还会报转义字符的错误

或者

${requestInfo.requestTime?date}

${requestInfo.requestTime?time}

${requestInfo.requestTime?datetime}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5434335.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存