spring i18n 设置时区

2021-06-18 23:04

阅读:399

标签: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;
}

}

 

 

 




spring i18n 设置时区

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

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


评论


亲,登录后才可以留言!