Freemarker:将日期从科学记数法转换为数字

Freemarker: Convert date from Scientific Notation to a number

我是一个完整的 Freemarker 新手,我正在使用一个使用 freemarker 模板的框架。我正在尝试根据某个字段 "date".

对哈希序列进行排序

我的输入 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>,出现以下错误:

Failed to "?eval" string with this error: ---begin-message--- Syntax error in ?eval-ed string in line 1, column 55: Encountered "E9", but was expecting one of: ".." ".." "," "}" "." "[" "(" "?" "!" "??" "+" "-" "" "/" "%" "!=" "=" "==" ">=" ">" ---end-message--- The failing expression: ==> fields[0]?eval [in template "89-1070010335" at line 1, column 14] ---- FTL stack trace ("~" means nesting-related)

我想做这样的事情:

<#assign j=fields[0]>
<#list j?sort_by("date") as i>
  ${i.date}: ${i.id}
</#list>

如何将日期字段从科学计数法转换为freemarker中的数字,然后根据该日期字段的值sort_by?

如果我能从 Freemarker documentation note.

中得到一些指示或任何特定的参考,我会很高兴

由于数据模型包含嵌套列表,因此我们必须在模板中采用嵌套列表指令,如下所示。

  <#list fields as field>
    <#list field?sort_by("date") as innerField>
      ${innerField.date?replace(",", "")} : ${innerField.id}
    </#list>
    </#list>

下面的代码片段将科学记数法转换为数字。

<#assign scientificFormat = "1.563426177E9">
<#assign number = scientificFormat?number?replace(",", "")>
${number}

来源:https://freemarker.apache.org/docs/ref_builtins_sequence.html