在写ftl模板代码时,有一个常见的功能,即后台返回一个列表,前端分页展示。如果列表项中有Date对象,直接展示会报错,这个时候需要对这个Date对象进行格式化处理。格式化处理有几种方法
- ?date
日期,没有具体到时间 - ?time
只有时间 - ?datetime
日期+时间 - ?string(regx)
按regx正则表达式格式化输出
举例:object对象有一个createTime属性,是一个date对象,需要在表格中展示出来。
<td>
<#if (object.createTime)??>
${(object.createTime?string('yyyy-MM-dd HH:mm:ss'))}
</#if>
</td>
本文介绍在FreeMarker模板中如何处理Date对象的显示问题。通过使用不同的格式化标记如?date、?time、?datetime及?string(regx),实现对日期时间的多样化展示。特别针对表格中的createTime属性进行了实例演示。
1万+

被折叠的 条评论
为什么被折叠?



