spring5配置时区
2020-12-07 本文已影响0人
cjlynn
@Configuration
public class RequestHandlerConfig extends WebMvcConfigurationSupport {
...
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.removeIf(c -> c instanceof MappingJackson2HttpMessageConverter);
converters.add(new MappingJackson2HttpMessageConverter(customObjectMapper()));
}
public ObjectMapper customObjectMapper() {
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder().timeZone(TimeZone.getDefault());
return builder.build();
}
}