@Component
public class FreeMarkerUtils{
private DateTimeFormatter DF_LONG = DateTimeFormat.forPattern("yyyyMMddHHmmss");
}
在
import com.jagregory.shiro.freemarker.ShiroTags;
import com.jsdc.zhly.common.utils.FreeMarkerUtils;
import freemarker.template.TemplateModelException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import javax.annotation.PostConstruct;
@Configuration
public class FreeMarkerConfig {
@Autowired
protected FreeMarkerConfigurer freeMarkerConfigurer;
@PostConstruct
public void setSharedVariable() throws TemplateModelException {
freeMarkerConfigurer.getConfiguration().setSharedVariable("utils", new FreeMarkerUtils());
//将freemarkerutils注入
}
}
在页面就可以直接用了
<div class="words">${utils.forPattern(date)}</div> 格式化日期
日期为空: ${(user.birthDate?string("yyyy-MM-dd"))!'无数据 '}
本文介绍如何在Spring框架中配置Freemarker模板引擎,通过自定义FreeMarkerUtils类实现日期格式化,并将其注入到Freemarker配置中,以便在页面上直接使用。同时展示了在页面上使用${utils.forPattern(date)}
2232

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



