简体   繁体   English

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

[英]Multiple template resolvers for thymeleaf on spring boot

I'm looking for a way to define two template resolvers that can be used for thymeleaf mail processing in a spring boot app. 我正在寻找一种方法来定义两个模板解析器,可以在spring boot应用程序中用于百万美元的邮件处理。 I need this because I have a html template and a text template. 我需要这个,因为我有一个html模板和一个文本模板。 Both are necessary to provide rich text and plain text content in the email. 两者都是在电子邮件中提供富文本和纯文本内容所必需的。

All configuration shall be done in application.properties or via environment properties. 所有配置都应在application.properties中或通过环境属性完成。

I've only managed to define one template resolver: 我只设法定义了一个模板解析器:

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

I would be glad if anyone could give me a hint or show me the right direction where to search for a solution. 如果有人能给我一个提示或向我展示寻找解决方案的正确方向,我会很高兴。

had the same topic and solved it thanks to the thymeleaf site. 有了相同的主题,并由于百里香的网站解决了它。 Visit http://www.thymeleaf.org/doc/articles/springmail.html 访问http://www.thymeleaf.org/doc/articles/springmail.html

Here is also a sample of the configuration: 这里还有一个配置示例:

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

The main method that you should look into is this one: 您应该研究的主要方法是:

/* ******************************************************************** */
/*  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;
}

Here are defined multiple template resolvers. 这里定义了多个模板解析器。

The con part is, that is java code and it is not handled over the application.properties way. con部分是java代码,它不是通过application.properties方式处理的。 If you find any way to define them in the application.properties ... leave a comment. 如果您在application.properties中找到任何方法来定义它们,请发表评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM