使用templateResolver发送电子邮件时,springMVC + thymleaf无法解析消息表达式

时间:2016-03-28 09:41:42

标签: templates spring-boot thymeleaf

application.properties是

spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
# set to false for hot refresh, should be set to true in deployment
spring.thymeleaf.cache=false

获取模板内容是这样的:

@Autowired
    private ITemplateResolver templateResolver;

private String getMailContent(EmailDTO email, EmailType type) {

    SpringTemplateEngine templateEngine = new SpringTemplateEngine();
    templateEngine.setTemplateResolver(templateResolver);
    Context context = new Context(email.getLocale());
    context.setVariable("email", email.getAddress());
    return templateEngine.process("email/resetcontent", context);

}

模板是:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<title>SIM : Reset Password</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
</head>
<body>
    <span th:text="#{reset.password.title}">Reset Password</span>
    <span th:text="${email}"></span>
</body>
</html>

th:text =“$ {email}”可以解析但是th:text =“#{reset.password.title}”是?? reset.password.title_en_US ??

Project Structure

谁能告诉我为什么?非常感谢你

1 个答案:

答案 0 :(得分:0)

如果您使用spring引导默认消息解析器,请尝试为具有“title”字段的“password”bean找到代码“reset”。

你应该使用这段代码:

 <span th:text="#{resetPasswordTitle}">Reset Password</span>