2016-03-28 10 views
0

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 ??なぜ私に言うことができる

Project Structure

+0

は$ {メール}はBeanオブジェクトと#{reset.password.title}と結合された参照であるプロパティ変数の解を渡さないように、あなたは、変数のプロパティを取得する必要がありますあなたのコントローラーで –

+0

はい、それは良い解決策ではありません、私はこの方法を一時的に使用します。あなたが他の方法を考えるなら、私に教えてください – zengshufang

答えて

0

デフォルトのメッセージリゾルバを使用している場合は、「タイトル」フィールドを持つ「パスワード」Beanのコードを「リセット」してみてください。

あなたはこのコードを使用する必要があります。

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

それは本当に春のブートです。私は試してみましたが、まだ稼働していません – zengshufang

+0

は、プログラムの起動時にautowired templateEngineを持っているので解決しました – zengshufang

+0

:) –

関連する問題