还是根据邮件发送模板,spring + freemaker 进行邮件的发送。之前有篇文章是记录普通的邮件发送的。就是对于我们要替换的字段进行直接的替换就好啦。
这里我们提到,对于想多行的,例如我们查询出一个列表,我们如何利用模板进行处理,并发送给相应的人。
这里用的多的就是freemaker的一些标签了。
1 我的模板p.ftl
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>客户列表</title>
<link href="css/index.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.STYLE2 {
color: #071890;
font-weight: bold;
}
-->
.maincontop {
clear: both;
width: 100%;
height: 26px;
}
.mainb7 {
font-weight: bold;
color: #152282;
}
.maincontop table {
}
.box .mainliegsyj .maincontop .maincontopgao a {
}
.mainconbg2 {
border-left:solid 1px #999999;
width:100%;clear:both;
}
.maincon2 {
}
.maincon2 span {
line-height: 22px;
height: 22px;
padding-left: 5px;
color: #000000;
text-align: right;
display: block;
padding-right: 6px;
}
.maincon2 li {
line-height: 22px;
height: 22px;
color: #000000;
display: block;
text-align: right;
text-indent: 8px;
list-style-type: none;
}
.maincon2 a {
color: #041c96;
text-decoration: none;
float: none;
margin-right: 0px;
}
.maincon2 td {
line-height: 22px;
height: 22px;
}
.maincon2 table tr td {
line-height: 22px;
height: 22px;
padding-left: 5px;
white-space: nowrap;
text-align: center;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #999999;
border-right-width: 1px;
border-right-style: solid;
border-right-color: #999999;
}
.maincon2 table {
color: #333333;
width: 100%;
}
.maincon2 a{
margin-right: auto;
margin-left: auto;
float: none;
color: #011c61;
}
.maincon2 a:active,
.maincon2 a:hover{
color: #990000;
text-decoration: none;
font-weight: normal;
}
.maincon2 span a {
float: left;
color: #011c61;
}
</style>
</head>
<body>
尊敬的客户<font color='red'>${tzgwName}</font>,您好:XXXXXXXXXXXXXX,谢谢。
<table width="100%" cellspacing="0" cellpadding="0">
<tr>
<td valign="top">
<div class="mainliegsyj">
<div class="maincontop">
<table width="100%" cellspacing="0" cellpadding="0">
<tr>
<td>
<div class="mainconbg2">
<div class="maincon2">
<table width="100%" cellspacing="0" cellpadding="0">
<tr align="center" bgcolor="#ebe9e8" class="mainb7">
<td align="center"><div>客户姓名</div></td>
<td align="center"><div>资金账号</div></td>
<td align="center"><div>客户手机</div></td>
<td align="center"><div>类型</div></td>
</tr>
<#list promtContents as item>
<tr bgcolor="#FFFFFF">
<td align="center">${item.name} </td>
<td align="center">${item.accountno} </td>
<td align="center">${item.mobile2} </td>
<td align="center">
<#if item.type == "1" >A<#else>B</#if>
</td>
</tr>
</#list>
</table>
</div>
</div>
</td>
</tr>
</table>
</div>
</div>
</td>
</tr>
</table>
</body>
</html>
2 对于上面得我们使用了
<#list promtContents as item>
..........................
</#list>
promtContents :我们查询出来的一个list了,里面当然是存了一些Pojo ,使用list标签进行遍历就可以了。输出是和jsp 中的标签类似。${item.属性}
<#if item.type == "1" >A<#else>B</#if> : 还有这个标签,if判断的,注意没有 { }哦