springboot之freemarker模板基本使用

1、在application.properties导入配置文件

spring:
#是否缓存
thymeleaf:
cache: false
freemarker:
# 设置模板后缀名
suffix: .ftl
# 设置文档类型
content-type: text/html
# 设置页面编码格式
charset: UTF-8
# 设置页面缓存
cache: false
# 设置ftl文件路径,默认是/templates,为演示效果添加role
template-loader-path: classpath:/templates

2、导入依赖包

org.springframework.boot spring-boot-starter-freemarker

3、基本使用




    
    角色权限



取值如果是null自动给值:你猜

welcome【${title !'你猜'}】to page

非空判断

<#if title?exists> 存在

条件表达式

<#if sex='girl'> 女 <#elseif sex='boy'> 男 <#else> 保密

循环

<#list list1 as role>
ID 名字 描述
${role.uid} ${role.userName} ${role.description}

include获取其他文件的值

<#include 'foot.ftl'>

freemarker模板引进项目名的获取名(全局变量以及局部变量的设置)

${springMacroRequestContext.contextPath} <#--global assign作用相当于c标签的set标签--> <#global ctx1> ${springMacroRequestContext.contextPath} <#assign ctx2> ${springMacroRequestContext.contextPath} ${ctx1}${ctx2}

你可能感兴趣的:(springboot之freemarker模板基本使用)