Freemarker配置全局变量1、重写freemarker配置
fig;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
常规化
slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import t.annotation.Configuration;
import org.springframework.web.rvlet.view.InternalResourceViewResolver;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
/
**
* 配置freemarker全局变量
*
* @author Zachary
* @date 2019-11-18 17:19
*/
@Slf4j
@Data
@Configuration
@NoArgsConstructor
@AllArgsConstructor
public class FreeMarkerConfig {
@Resource
plate.Configuration configuration;
private InternalResourceViewResolver resourceViewResolver;
// @Value("${ctx}")羊肉串的做法
// private String ctx;
@Value("${website.version}")
private String version;
/**
* Spring 初始化的时候加载配置
自制方便面*
* @throws Exception
*/
@PostConstruct
public void tConfigure()throws Exception {
大腿拉伤怎么办
// 加载html的资源路径
// configuration.tSharedVariable("ctx", ctx);
configuration.tSharedVariable("version", version);
}
}
2、编写⼀个.ftl页⾯读取配置
<!DOCTYPE html>
水晶功效
对祖国的寄语
<html lang="zh"th="www.thymeleaf"> <head>
缘交<meta chart="UTF-8">
<title>Title</title>
</head>
<body>
${version}
</body>
没有明天</html>
3、效果