Spring LocaleContextHolder.setLocale void无法转换为区域设置
当我试图将Locale设置为Locale.US时,我得到一个错误,void无法转换为Locale。但是Locale.US不是空的。如果我将setLocale更改为getLocale(),一切正常。这是因为 因此,只需将其设置在那里,并在下面获取:Spring LocaleContextHolder.setLocale void无法转换为区域设置,spring,spring-mvc,internationalization,Spring,Spring Mvc,Internationalization,当我试图将Locale设置为Locale.US时,我得到一个错误,void无法转换为Locale。但是Locale.US不是空的。如果我将setLocale更改为getLocale(),一切正常。这是因为 因此,只需将其设置在那里,并在下面获取: @RequestMapping(method = RequestMethod.GET) public ModelAndView viewMain(Locale locale) { Locale currentLocale =
@RequestMapping(method = RequestMethod.GET)
public ModelAndView viewMain(Locale locale) {
Locale currentLocale = LocaleContextHolder.setLocale(Locale.US);
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("locale", currentLocale);
LOG.info("main " /* + name*/ + "page shown");
modelAndView.setViewName("main_page");
return modelAndView;
}
这是因为
因此,只需将其设置在那里,并在下面获取:
@RequestMapping(method = RequestMethod.GET)
public ModelAndView viewMain(Locale locale) {
Locale currentLocale = LocaleContextHolder.setLocale(Locale.US);
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("locale", currentLocale);
LOG.info("main " /* + name*/ + "page shown");
modelAndView.setViewName("main_page");
return modelAndView;
}
可能的重复可能的重复