java ReloadableResourceBundleMessageSource。getMessage()不使用我给它的参数
我正在使用ReloadableResourceBundleMessageSource
来支持多种语言
我无法将参数“发送”到ReloadableResourceBundleMessageSource.getMessage()
以“构建”消息
我在屏幕上看到的消息是the fields are {0} and {1}
,但我希望看到the fields are name and surname
重要提示:在我的场景中,我不能使用spring:message
,我必须以编程方式打印消息
这是中定义的bean。xml文件:
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>WEB-INF/I18n/dao/dao</value>
</list>
</property>
<property name="defaultEncoding" value="UTF-8" />
<property name="cacheSeconds" value="1"/>
</bean>
这是我调用ReloadableResourceBundleMessageSource.getMessage()
的类
public class I18nMessageHandler {
@Autowired
private ReloadableResourceBundleMessageSource messageSource;
public String printMessage() {
...
return messageSource.getMessage("messageA", new Object[] { "name", "surname" }, LocaleContextHolder.getLocale());
...
}
}
这是控制器,我在这里调用I18nMessageHandler.printMessage()
@Controller
public class indexController {
@Autowired
private I18nMessageHandler i18nMessageHandler;
@RequestMapping("/index")
public String index(Model model) {
model.addAttribute("message", i18nMessageHandler.printMessage());
return "index";
}
}
这是jsp页面
${message}
这是文件属性:
messageA = the fields are {0} and {1}
你能发现我的错误吗
多谢各位
共 (0) 个答案