springboot 整合 FreeMaker

springboot 整合 FreeMaker

  1. maven依赖
    <!--freemarker-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-freemarker</artifactId>
    </dependency>   
  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

<!-- freemarker + shiro(标签) begin -->
<dependency>
    <groupId>net.mingsoft</groupId>
    <artifactId>shiro-freemarker-tags</artifactId>
    <version>0.1</version>
</dependency>
<!-- freemarker + shiro(标签) begin -->
@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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值