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