ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
java thymeleaf 邮件模板 email ### 模板 `email/index.html` ``` <!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <p>hello 欢迎 <span th:text="${username}"></span>加入 XXX 集团,您的入职信息如下:</p> <table border="1"> <tr> <td>职位</td> <td th:text="${position}"></td> </tr> <tr> <td>薪水</td> <td th:text="${salary}"></td> </tr> </table> </body> </html> ``` ***** ### 渲染 ``` package com.youge; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.thymeleaf.TemplateEngine; import org.thymeleaf.context.Context; @SpringBootTest class SpringbootThymeleafApplicationTests { @Autowired TemplateEngine templateEngine; @Test void contextLoads() { } @Test public void emailTemplateTest(){ Context context = new Context(); context.setVariable("username","张三三"); context.setVariable("position","Java Engine"); context.setVariable("salary",99999); String mail = templateEngine.process("email/index", context); System.out.println(mail); } } ```