<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <a href="" th:href="@{https://www.jianshu.com/u/{id}(id=${id})}">激活帐号</a> </body> </html>
测试
@Autowired TemplateEngine templateEngine; Context context=new Context(); context.setVariable("id","f192766abeab"); String emailContent=templateEngine.process("emailTemplate",context); mailService.sendHtmlMail("邮箱","主题",emailContent);
语法HTML th:href:
href地址:@{路径/{id}(id=${id})}
HTML邮件模板:
支持包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
创建HTML中:
<html lang="en" xmlns:th="thymel官网路径(http://www.thymeleat.otg)"> :可以使用thymel,thymel是以th标签开头
注:thymel有个特点,所以元素必须闭合,不然会报错
java代码:
TemplateEngine templateEngine:用于解析模板文件
Context context = new Context();
context.setVariable('id','id值'); //设置id
读取文本HTML:String eamilContext =templateEngine.process("模板名字(HTML名字)",context)
thymeleaf的用法我学到了,之前用的都是参数形式,没想到还能用
·templateEngine.process("html名",传入参数)·