版本:org.freemarker:freemarker:2.3.28
import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapper;
import freemarker.template.SimpleDate;
import freemarker.template.TemplateModel;
import freemarker.template.TemplateModelException;
import org.springframework.beans.factory.annotation.Autowired;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
@Autowired
public void configureFreemarker(Configuration configuration) {
configuration.setObjectWrapper(new DefaultObjectWrapper(Configuration.VERSION_2_3_28) {
@Override
public TemplateModel wrap(Object object) throws TemplateModelException {
if (object instanceof LocalDate) {
return new SimpleDate(Date.valueOf((LocalDate) object));
}
if (object instanceof LocalTime) {
return new SimpleDate(Time.valueOf((LocalTime) object));
}
if (object instanceof LocalDateTime) {
return new SimpleDate(Timestamp.valueOf((LocalDateTime) object));
}
return super.wrap(object);
}
});
}
(完)
4553



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



