码迷,mamicode.com
首页 > 编程语言 > 详细

spring i18n 设置时区

时间:2018-09-26 12:58:44      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:work   ISE   exce   let   handle   actor   simple   debug   local   

public class TimeZoneChangeInterceptor extends HandlerInterceptorAdapter {

public static final String DEFAULT_PARAM_NAME = "_timeZone";
private static final Logger logger = LoggerFactory.getLogger(TimeZoneChangeInterceptor.class);

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws ServletException {

String newTimeZone = request.getParameter(DEFAULT_PARAM_NAME);
if (StringUtils.isEmpty(newTimeZone)) return true;

TimeZone timeZone = TimeZone.getTimeZone(newTimeZone.toUpperCase());
if (timeZone != null) {
logger.debug("CHANGE TIMEZONE:" + LocaleContextHolder.getTimeZone().getID() + " TO " + timeZone.getID());
LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);

if (localeResolver instanceof LocaleContextResolver) {
((LocaleContextResolver) localeResolver).setLocaleContext(request, response, new SimpleTimeZoneAwareLocaleContext(LocaleContextHolder.getLocale(), timeZone));
}
}

return true;
}

}

 

 

 

<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
<bean class="xxx.xxx.xxx.support.spring.i18n.TimeZoneChangeInterceptor"/>
</mvc:interceptors>

spring i18n 设置时区

标签:work   ISE   exce   let   handle   actor   simple   debug   local   

原文地址:https://www.cnblogs.com/wangtg/p/9706131.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!