java spring boot- freemarker 配置 yml使用流程
1、pom.xml 加入maven 依赖
<!-- 引入 freemarker 模板依赖 --><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId></dependency>
2、执行更新

3、在application.yml 中添加 feemarker 配置
spring: freemarker: allow-request-override: false cache: true check-template-location: true charset: UTF-8 suffix: .html templateEncoding: UTF-8 templateLoaderPath: classpath:/templates/ content-type: text/html expose-request-attributes: false expose-session-attributes: false expose-spring-macro-helpers: false4、控制器代码
@GetMapping(value = "/my")
public ModelAndView my(ModelMap modelMap){
ModelAndView mv = new ModelAndView("pay");
modelMap.addAttribute("name","pengxingjiang");
mv.addObject("address","四川-宜宾");
HashMap<String,String> userInfo = new HashMap<>();
userInfo.put("name","111");
userInfo.put("tel","18888888888");
mv.addObject("userInfo",userInfo);
return mv;
}5、视图文件代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
${name}
${address}
========
${userInfo.name}
${userInfo.tel}
</body>
</html> 相关推荐
81314797 2020-11-18
89314493 2020-11-03
81941231 2020-09-17
thisisid 2020-09-09
如狼 2020-08-15
82384399 2020-06-16
86384798 2020-05-12
80183053 2020-05-02
86384798 2020-04-26
86384798 2020-04-11
rionchen 2020-04-09
86384798 2020-04-07
86384798 2020-04-04
80183053 2020-03-07
87201943 2020-03-06
83961233 2020-02-26
87201943 2020-02-21