spring boot 下获取thymeleaf 渲染后的html字符串

在发送邮件时需要直接获取thymeleaf渲染后的html字符串,实现方法如下:
基础条件:项目中引入thymeleaf依赖

src\main\resources\templates\test.html




    
    spring boot-thymeleaf test



测试:

@SpringBootTest
class JzApplicationTests {
    @Autowired
    private TemplateEngine templateEngine;

    @Test
    void thymeleaf() {
        Context context = new Context();
        context.setVariable("name", "xxxxxxxxx");
        String result = templateEngine.process("test", context);
        System.out.println(result);
    }
}

你可能感兴趣的:(spring boot 下获取thymeleaf 渲染后的html字符串)