springboot 整合 FreeMaker

springboot 整合 FreeMaker

  1. maven依赖
    
    
        org.springframework.boot
        spring-boot-starter-freemarker
       
  1. application.yml
spring:
  freemarker:
    expose-request-attributes: true
    request-context-attribute: request #访问request
    cache: false
    charset: UTF-8
    content-type: text/html
    enabled: true
    template-loader-path: classpath:/templates/ #模板加载路径 按需配置
    suffix: .ftl
    expose-request-attributes: true  #expose:暴露
    request-context-attribute: request #访问request
    设置以上两个属性,就可以在ftl页面上获取项目根路径
    ${request.contextPath}

Freemaker FTL指令常用标签及语法
contains 是 string 的方法,对于List,Collection 应该使用seq_contains0
https://blog.csdn.net/pengpengpeng85/article/details/52070602

springboot使用freemaker shiroTag(先要配置shiro整合)
maven



    net.mingsoft
    shiro-freemarker-tags
    0.1


@Component
public class FreeMarkerConfigExtend implements InitializingBean {

    @Autowired
    private Configuration configuration;

    @Autowired
    private FreeMarkerViewResolver resolver;

    @Override
    public void afterPropertiesSet() throws Exception {
        // 加上这句后,可以在页面上使用shiro标签
        configuration.setSharedVariable("shiro", new ShiroTags());
    }
}

https://blog.csdn.net/sayoko06/article/details/80897658
https://www.sojson.com/blog/143.html

Freemarker新手教程
https://blog.csdn.net/qq_23994787/article/details/77506980

你可能感兴趣的:(FreeMaker,springboot)