当前位置: 首页 > news >正文

Freemaker 模板

背景
发送邮件,正文利用freemaker完成

 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>@Autowired
private Configuration configurer;@GetMapping("/test")public void test() throws Exception{Map<String, Object> map = new HashMap<>();map.put("test", "王五");map.put("url", "https://www.baidu.com/");List<VideoVo> deptList = new LinkedList<>();VideoVo videoVo = new VideoVo();videoVo.setName("深圳");videoVo.setOne("1");videoVo.setTwo("2");videoVo.setThree("3");videoVo.setFour("4");deptList.add(videoVo);VideoVo videoVo2 = new VideoVo();videoVo2.setName("广东");videoVo2.setOne("11");videoVo2.setTwo("22");videoVo2.setThree("33");videoVo2.setFour("44");deptList.add(videoVo2);map.put("deptList", deptList);map.put("autoFilds",true);String content = getContent("Mail.ftl", map);Template template = configurer.getTemplate("Mail.ftl");FileWriter fileWriter = new FileWriter(new File("D:\\IdeaProjects\\springboot_cache\\src\\main\\resources\\templates", "1.html"));template.process(map,fileWriter);
}public String getContent(String templateName, Map<String, Object> data) throws Exception {// 获取模板Template template = configurer.getTemplate(templateName);// 填充数据并把模板转为字符串return FreeMarkerTemplateUtils.processTemplateIntoString(template, data);
}
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8">
</head>
<body>
<div><p style="color: red">${test} 你好</p><p style="color: black"> &#160; &#160; &#160; &#160; &#160; Wecome to gaungdong</p><p style="color: black"><a href="${url}">查看图片</p><#if deptList ?? && deptList?size gt 0><#if autoFilds><table align="center" cellpadding="0" border="1" width="100%" ;><tr><th rowspan="2">机构</th><th colspan="2">当月</th><th colspan="2">当年</th></tr><tr><th style="display: none">机构</th><th>我司</th><th>人保</th><th>太保</th><th>人保</th></tr><#list deptList as dept><tr><td align="center">${dept.name}</td><td align="center">${dept.one}</td><td align="center">${dept.two}</td><td align="center">${dept.three}</td><td align="center">${dept.four}</td></tr></#list></table><#else><table align="center" cellpadding="0" border="1" width="100%" ;><tr><th rowspan="2">板块</th><th colspan="2">当月</th><th colspan="2">当年</th></tr><tr><th style="display: none">机构</th><th>我司</th><th>人保</th><th>太保</th><th>人保</th></tr><#list deptList as dept><td align="center">${dept.name}</td><td align="center">${dept.one}</td><td align="center">${dept.two}</td><td align="center">${dept.three}</td><td align="center">${dept.four}</td></#list></table></#if></#if>
</div></body>
</html>

演示效果

相关文章:

  • 机器学习补充
  • python离线安装第三方库、及其依赖库(单个安装,非批量移植)
  • 基于esp-idf的arm2d移植
  • 计算机编码以及URL转码
  • C语言王国——深入自定义类型(联合体、枚举)
  • 一款Wordpress网站导航主题,带昼夜切换功能
  • .NET C# 使用GDAL读取FileGDB要素类
  • Spring Boot集成tablesaw插件快速入门
  • 2024广东省职业技能大赛云计算赛项实战——Ceph集群部署
  • 微信小程序-scroll-view实现上拉加载和下拉刷新
  • 细说MCU定时器中断的实现方法
  • Java18新特性(极简)
  • 在Linux/Ubuntu/Debian中使用SSH连接远程服务器VPS
  • curl命令使用
  • 活出属于自己的人生
  • 【Leetcode】104. 二叉树的最大深度
  • Android单元测试 - 几个重要问题
  • Centos6.8 使用rpm安装mysql5.7
  • Dubbo 整合 Pinpoint 做分布式服务请求跟踪
  • ECMAScript 6 学习之路 ( 四 ) String 字符串扩展
  • E-HPC支持多队列管理和自动伸缩
  • happypack两次报错的问题
  • java2019面试题北京
  • JavaScript工作原理(五):深入了解WebSockets,HTTP/2和SSE,以及如何选择
  • jQuery(一)
  • MobX
  • MyEclipse 8.0 GA 搭建 Struts2 + Spring2 + Hibernate3 (测试)
  • MySQL用户中的%到底包不包括localhost?
  • React的组件模式
  • Spring思维导图,让Spring不再难懂(mvc篇)
  • Vue 重置组件到初始状态
  • vue-cli在webpack的配置文件探究
  • 阿里云购买磁盘后挂载
  • 读懂package.json -- 依赖管理
  • 分享一个自己写的基于canvas的原生js图片爆炸插件
  • 开源地图数据可视化库——mapnik
  • 扑朔迷离的属性和特性【彻底弄清】
  • 如何用vue打造一个移动端音乐播放器
  • 事件委托的小应用
  •  一套莫尔斯电报听写、翻译系统
  • 做一名精致的JavaScripter 01:JavaScript简介
  • Nginx实现动静分离
  • 国内唯一,阿里云入选全球区块链云服务报告,领先AWS、Google ...
  • 整理一些计算机基础知识!
  • ​520就是要宠粉,你的心头书我买单
  • ​Linux·i2c驱动架构​
  • !!Dom4j 学习笔记
  • #Java第九次作业--输入输出流和文件操作
  • #NOIP 2014# day.1 T2 联合权值
  • #我与Java虚拟机的故事#连载03:面试过的百度,滴滴,快手都问了这些问题
  • ${factoryList }后面有空格不影响
  • (5)STL算法之复制
  • (a /b)*c的值
  • (附源码)ssm高校志愿者服务系统 毕业设计 011648
  • (规划)24届春招和25届暑假实习路线准备规划