WebMvcConfig.java 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //package com.platform.yijia.config;
  2. //
  3. //import com.fasterxml.jackson.databind.DeserializationFeature;
  4. //import com.fasterxml.jackson.databind.ObjectMapper;
  5. //import com.fasterxml.jackson.databind.PropertyNamingStrategy;
  6. //import com.fasterxml.jackson.databind.module.SimpleModule;
  7. //import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
  8. //import org.springframework.beans.factory.annotation.Autowired;
  9. //import org.springframework.beans.factory.annotation.Value;
  10. //import org.springframework.context.annotation.Bean;
  11. //import org.springframework.context.annotation.Configuration;
  12. //import org.springframework.http.converter.HttpMessageConverter;
  13. //import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
  14. //import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
  15. //
  16. //import java.text.SimpleDateFormat;
  17. //import java.util.List;
  18. //import java.util.TimeZone;
  19. //
  20. ///**
  21. // * 添加与WebMvc相关的自定义配置
  22. // */
  23. //@Configuration
  24. //public class WebMvcConfig extends WebMvcConfigurationSupport {
  25. //
  26. // @Value("${spring.jackson.date-format}")
  27. // private String dateFormatPattern;
  28. //
  29. // @Value("${spring.jackson.time-zone}")
  30. // private String timeZone;
  31. //
  32. // @Override
  33. // protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
  34. // MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
  35. // ObjectMapper objectMapper = converter.getObjectMapper();
  36. // // 生成JSON时,将所有Long转换成String
  37. // SimpleModule simpleModule = new SimpleModule();
  38. // simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
  39. // simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
  40. // objectMapper.registerModule(simpleModule);
  41. // // 时间格式化
  42. // objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  43. // //这个可以引用spring boot yml 里的格式化配置和时区配置
  44. // objectMapper.setDateFormat(new SimpleDateFormat(dateFormatPattern));
  45. // objectMapper.setTimeZone(TimeZone.getTimeZone(timeZone));
  46. // // 设置格式化内容
  47. // converter.setObjectMapper(objectMapper);
  48. // converters.add(0, converter);
  49. // super.extendMessageConverters(converters);
  50. // }
  51. //
  52. //}