@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"))!'无数据 '}