application.propertiesを送信する際、メッセージ式を解析springMVC + thymleafが使用templateResolverは、電子メール
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
のgetテンプレートコンテンツであることができないことは、このようなものです:
@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 ??なぜ私に言うことができる
?
は$ {メール}はBeanオブジェクトと#{reset.password.title}と結合された参照であるプロパティ変数の解を渡さないように、あなたは、変数のプロパティを取得する必要がありますあなたのコントローラーで –
はい、それは良い解決策ではありません、私はこの方法を一時的に使用します。あなたが他の方法を考えるなら、私に教えてください – zengshufang