Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding Locale from Controller in Spring MVC

I'm using Sprinng 3.0.

How do I find the current locale set by a LocaleResolver within an annotation-based controller?

Thanks.

like image 206
Tom Tucker Avatar asked Oct 22 '10 17:10

Tom Tucker


2 Answers

LocaleContextHolder can be used, especially to obtain the Locale outside of a controller method.

Locale locale = LocaleContextHolder.getLocale();
like image 129
Unmitigated Avatar answered Sep 21 '22 09:09

Unmitigated


You can declare an argument of type Locale in your controller method:

@RequestMapping
public ModelAndView foo(..., Locale locale) { ... }

See also:

  • 15.3.2.3 Supported handler method arguments and return types
like image 21
axtavt Avatar answered Sep 22 '22 09:09

axtavt