是否可以从速度模板的属性文件中动态读取静态文本?
问题内容:
问候所有我有一个Java EE应用程序(弹簧框架),该应用程序使用包含静态文本的vm模板,例如:
<span> hello world </span>
是这样的:
<span> <fmt:message key="hi.message" /> </span>
而且我想知道是否有可能像JSP中那样根据用户区域设置从属性文件(en / fr)中读取文本,因此我将对所有区域设置使用一个模板,并且文本是动态的
注意:速度不是我在应用程序中使用的视图技术,我仅在发送电子邮件时使用它的模板。
问题答案:
我们无法在网络应用程序外部使用宏,例如在我的情况下,因此解决方案是使用messageSource
model.put("messagesource", this.messagesource);
// adding this e.g. should do the trick
model.put("keyHelloCustomer", "the_key_you_use_in_your_properties_file");
model.put("noArgs", new Object[]{});
model.put("locale", yourOwnPrivateMethodToDetermineWhichLocaleToUse());
并在vm中:
${messageSource.getMessage($keyHelloCustomer, $noArgs, $locale)}
参考:http :
//forum.springsource.org/showthread.php?t=82018