import org.joda.time.base.AbstractInstant;import freemarker.template.DefaultObjectWrapper;import freemarker.template.SimpleDate;import freemarker.template.TemplateDateModel;import freemarker.template.TemplateModel;import freemarker.template.TemplateModelException;@SuppressWarnings("deprecation")public class JodaTimeObjectWrapper extends DefaultObjectWrapper { @Override public TemplateModel wrap(final Object obj) throws TemplateModelException { if (obj instanceof AbstractInstant) return new SimpleDate(((AbstractInstant) obj).toDate(), TemplateDateModel.DATETIME); return super.wrap(obj); }}
spring boot配置:
#freemarker freemarker: settings: object_wrapper: com.lowff.halo.basic.freemarker.JodaTimeObjectWrapper datetime_format: yyyy-MM-dd HH:mm:ss date_format: yyyy-MM-dd time_format: HH:mm:ss