【发布时间】:2020-08-02 22:34:13
【问题描述】:
我是一个完整的 Freemarker 新手,我正在使用一个使用 freemarker 模板的框架。我正在尝试根据某个字段“日期”对哈希序列进行排序。
我的输入 json 如下所示:
{"fields": [
[
{
"contentType": "application/json",
"date": 1.563457325E9,
"id": "abc",
"size": 0.0
},
{
"contentType": "application/json",
"date": 1.563426843E9,
"id": "def",
"size": 0.0
},
{
"contentType": "application/json",
"date": 1.563454092E9,
"id": "ghi",
"size": 0.0
},
{
"contentType": "application/json",
"date": 1.563425862E9,
"id": "jkl",
"size": 0.0
},
{
"contentType": "application/json",
"date": 1.563426128E9,
"id": "mno",
"size": 0.0
},
{
"contentType": "application/json",
"date": 1.563453696E9,
"id": "pqr",
"size": 0.0
},
{
"contentType": "application/json",
"date": 1.563426813E9,
"id": "stu",
"size": 0.0
},
{
"contentType": "application/json",
"date": 1.563426177E9,
"id": "vwx",
"size": 0.0
}
]
]
}
当我尝试这样做时:<#assign j=fields[0].eval>,我收到以下错误:
“?eval”字符串失败,出现以下错误:---begin-message--- 语法 第 1 行第 55 列的 ?eval-ed 字符串中的错误:遇到“E9”,但是 期待以下之一:“..”“..”“”“}”“。” "[" "(" “?” “!” “??” "+" "-" "" "/" "%" "!=" "=" "==" ">=" ">" ---end-message--- 失败的表达式:==> fields[0]?eval [in template "89-1070010335" at line 1, column 14] ---- FTL 堆栈跟踪(“~”表示嵌套相关)
我想做这样的事情:
<#assign j=fields[0]>
<#list j?sort_by("date") as i>
${i.date}: ${i.id}
</#list>
如何将日期字段从科学计数法转换为freemarker中的数字,然后根据该日期字段的值进行排序?
如果我能从Freemarker documentation note 获得一些指针或任何特定参考,我会很高兴。
【问题讨论】:
标签: freemarker