标签: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>
标签:work ISE exce let handle actor simple debug local
原文地址:https://www.cnblogs.com/wangtg/p/9706131.html