spring 国际化
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <!-- 国际化信息所在的文件名 --> <property name="basename" value="messages" /> <!-- 如果在国际化资源文件中找不到对应代码的信息,就用这个代码作为名称 --> <property name="useCodeAsDefaultMessage" value="true" /> </bean>
@Controller @RequestMapping(value = "/global") public class GlobalController { @RequestMapping(value="/test", method = {RequestMethod.GET}) public String test(HttpServletRequest request,Model model){ if(!model.containsAttribute("contentModel")){ //从后台代码获取国际化信息 RequestContext requestContext = new RequestContext(request); model.addAttribute("money", requestContext.getMessage("money")); model.addAttribute("date", requestContext.getMessage("date")); FormatModel formatModel=new FormatModel(); formatModel.setMoney(12345.678); formatModel.setDate(new Date()); model.addAttribute("contentModel", formatModel); } return "globaltest"; } }