网站首页 > 知识剖析 正文
背景
发送邮件,正文利用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制作一张能在网上浏览的动态数据报表
- 最近发表
-
- PHP 8新特性之Attributes(注解),你掌握了吗?
- PHP + Redis 高并发轮盘抽奖系统实现
- PHP设计模式之原型模式(php 模型)
- php8 throw 表达式使用教程(php表达式的定义)
- php8 枚举使用教程(php枚举类型)
- GIMP 教程:如何创建照片文字效果(gimp怎么修改图片上的数字)
- 分享几个漂亮的宇宙风格的按钮动画效果,让你喜欢上CSS
- 一次示范就能终身掌握!让手机AI轻松搞定复杂操作丨浙大vivo出品
- Shanghai supports exporters' pivot as US tariffs hit trade flows
- 如何早期识别「快速进展性痴呆」?这些独特的特征可能提供重要线索 | AAN 2025
- 标签列表
-
- 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)