网站首页 > 知识剖析 正文
背景
发送邮件,正文利用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);
}
ftl模板
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<div>
<p style="color: red">${test} 你好</p>
<p style="color: black"> 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>
运行效果
- 上一篇: 伊朗呼吁土耳其立即终止对叙军事行动
- 下一篇: 你的自我界限够强大吗?
猜你喜欢
- 2024-12-04 你的自我界限够强大吗?
- 2024-12-04 伊朗呼吁土耳其立即终止对叙军事行动
- 2024-12-04 深入跨域 - 解决方案
- 2024-12-04 百度工程师教你玩转设计模式(单例模式)
- 2024-12-04 今年冬天火了一种“懒人穿法”:羽绒服+无痕裤,时髦显瘦还保暖
- 2024-12-04 基于Chrome内置AI的Web应用开发
- 2024-12-04 一行代码实现display"过渡动画"原理
- 2024-12-04 JavaScript中的父节点操作
- 2024-12-04 前端开发:DOM操作与页面元素交互
- 2024-12-04 如何用Excel制作一张能在网上浏览的动态数据报表
- 最近发表
-
- 表格存储 SQL 查询多元索引(表格存储 sql 查询多元索引的方法)
- 数据库教程-SQL Server多条件模糊查询
- Twitch宣布放弃Flash并逐步转型至HTML5平台
- 移动平台最强播放器MX Player:终于支持安卓5.0了!
- win10 NFS+黑群晖远程加载管理Windows文件夹(读写NTFS格式+高清播放器)
- Android端VLC 3.3版本发布,重新设计播放器界面
- 不仅仅被苹果封杀!Youtube宣布迁移Flash
- 揭开网站背后的魔法:B/S系统原来这么简单!
- Adobe Animate (An) 2020网页设计软件下载和安装教程
- Adobe发布“巨量”安全更新:遏制Flash“祸害”Linux
- 标签列表
-
- xml (46)
- css animation (57)
- array_slice (60)
- htmlspecialchars (54)
- position: absolute (54)
- datediff函数 (47)
- array_pop (49)
- jsmap (52)
- toggleclass (43)
- console.time (63)
- .sql (41)
- ahref (40)
- js json.parse (59)
- html复选框 (60)
- css 透明 (44)
- css 颜色 (47)
- php replace (41)
- css nth-child (48)
- min-height (40)
- xml schema (44)
- css 最后一个元素 (46)
- location.origin (44)
- table border (49)
- html tr (40)
- video controls (49)