多个模板旋转变压器为春季靴子上的百里香

mag*_*omi 5 spring thymeleaf spring-boot

我正在寻找一种方法来定义两个模板解析器,可以在spring boot应用程序中用于百万美元的邮件处理.我需要这个,因为我有一个html模板和一个文本模板.两者都是在电子邮件中提供富文本和纯文本内容所必需的.

所有配置都应在application.properties中或通过环境属性完成.

我只设法定义了一个模板解析器:

spring.thymeleaf.check-template-location=true
spring.thymeleaf.prefix=classpath:/mails/
spring.thymeleaf.excluded-view-names=
spring.thymeleaf.view-names=
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=true
Run Code Online (Sandbox Code Playgroud)

如果有人能给我一个提示或向我展示寻找解决方案的正确方向,我会很高兴.

小智 3

有相同的主题并通过百里香网站解决了它。访问http://www.thymeleaf.org/doc/articles/springmail.html

这也是一个配置示例:

https://github.com/thymeleaf/thymeleafexamples-springmail/blob/3.0-master/src/main/java/thymeleafexamples/springmail/business/SpringMailConfig.java

您应该研究的主要方法是:

/* ******************************************************************** */
/*  THYMELEAF-SPECIFIC ARTIFACTS FOR EMAIL                              */
/*  TemplateResolver(3) <- TemplateEngine                               */
/* ******************************************************************** */

@Bean
public TemplateEngine emailTemplateEngine() {
    final SpringTemplateEngine templateEngine = new SpringTemplateEngine();
    // Resolver for TEXT emails
    templateEngine.addTemplateResolver(textTemplateResolver());
    // Resolver for HTML emails (except the editable one)
    templateEngine.addTemplateResolver(htmlTemplateResolver());
    // Resolver for HTML editable emails (which will be treated as a String)
    templateEngine.addTemplateResolver(stringTemplateResolver());
    // Message source, internationalization specific to emails
    templateEngine.setTemplateEngineMessageSource(emailMessageSource());
    return templateEngine;
}
Run Code Online (Sandbox Code Playgroud)

这里定义了多个模板解析器。

缺点是,这是java代码,它不是通过application.properties方式处理的。如果您找到任何方法在 application.properties 中定义它们...请发表评论。