当前位置: 首页 > news >正文

网站建设哪里有学龙岗菠菜网站建设

网站建设哪里有学,龙岗菠菜网站建设,做地铁系统集成的公司网站,室内设计培训学费在json对象转换方面#xff0c;springboot默认使用的是MappingJackson2HttpMessageConverter。常规需求#xff0c;在工程中使用阿里的FastJson作为json对象的转换器。 FastJson SerializerFeatures WriteNullListAsEmpty #xff1a;List字段如果为null,输出为[],而非nu…在json对象转换方面springboot默认使用的是MappingJackson2HttpMessageConverter。常规需求在工程中使用阿里的FastJson作为json对象的转换器。 FastJson SerializerFeatures WriteNullListAsEmpty  List字段如果为null,输出为[],而非null WriteNullStringAsEmpty 字符类型字段如果为null,输出为,而非null DisableCircularReferenceDetect 消除对同一对象循环引用的问题默认为false如果不配置有可能会进入死循环 WriteNullBooleanAsFalseBoolean字段如果为null,输出为false,而非null WriteMapNullValue是否输出值为null的字段,默认为false。 public enum SerializerFeature {QuoteFieldNames,UseSingleQuotes,WriteMapNullValue,WriteEnumUsingToString,WriteEnumUsingName,UseISO8601DateFormat,WriteNullListAsEmpty,WriteNullStringAsEmpty,WriteNullNumberAsZero,WriteNullBooleanAsFalse,SkipTransientField,SortField,/** deprecated */DeprecatedWriteTabAsSpecial,PrettyFormat,WriteClassName,DisableCircularReferenceDetect,WriteSlashAsSpecial,BrowserCompatible,WriteDateUseDateFormat,NotWriteRootClassName,/** deprecated */DisableCheckSpecialChar,BeanToArray,WriteNonStringKeyAsString,NotWriteDefaultValue,BrowserSecure,IgnoreNonFieldGetter,WriteNonStringValueAsString,IgnoreErrorGetter,WriteBigDecimalAsPlain,MapSortField; } 使用FastJson有两种常规操作。 一、注入bean的方式这种方法加入的转换器排序是第一位 package com.gaoshan.verification.config;import org.springframework.context.annotation.Configuration; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;import java.util.List;Configuration public class WebMvcConfigurerConfig implements WebMvcConfigurer {Overridepublic void extendMessageConverters(ListHttpMessageConverter? converters) {for (HttpMessageConverter? messageConverter : converters) {System.out.println(messageConverter);}} } package com.gaoshan.verification.config;import com.alibaba.fastjson.serializer.SerializerFeature; import com.alibaba.fastjson.support.config.FastJsonConfig; import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; import org.springframework.boot.autoconfigure.http.HttpMessageConverters; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.MediaType;import java.util.ArrayList; import java.util.List;Configuration public class MessageConvertConfig {Beanpublic HttpMessageConverters fastJsonHttpMessageConverters() {FastJsonHttpMessageConverter fastConverter new FastJsonHttpMessageConverter();FastJsonConfig fastJsonConfig new FastJsonConfig();fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat,SerializerFeature.DisableCircularReferenceDetect,SerializerFeature.WriteBigDecimalAsPlain,SerializerFeature.WriteMapNullValue);fastConverter.setFastJsonConfig(fastJsonConfig);ListMediaType supportedMediaTypes new ArrayList();supportedMediaTypes.add(MediaType.APPLICATION_JSON);fastConverter.setSupportedMediaTypes(supportedMediaTypes);return new HttpMessageConverters(fastConverter);} }com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter2c5708e7 org.springframework.http.converter.ByteArrayHttpMessageConverter4ffa078d org.springframework.http.converter.StringHttpMessageConverter4e26564d org.springframework.http.converter.ResourceHttpMessageConverter42238078 org.springframework.http.converter.ResourceRegionHttpMessageConverter5627b8eb org.springframework.http.converter.xml.SourceHttpMessageConverter49fe0bcd org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter3516b881 org.springframework.http.converter.json.MappingJackson2HttpMessageConverter6be8ce1b org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConvertere3c36d 二、实现WebMvcConfigurer接口这种方法加入的转换器排序是最后一位 package com.gaoshan.verification.config;import com.alibaba.fastjson.serializer.SerializerFeature; import com.alibaba.fastjson.support.config.FastJsonConfig; import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; import org.springframework.context.annotation.Configuration; import org.springframework.http.MediaType; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;import java.util.ArrayList; import java.util.List;Configuration public class WebMvcConfigurerConfig implements WebMvcConfigurer {Overridepublic void extendMessageConverters(ListHttpMessageConverter? converters) {for (HttpMessageConverter? messageConverter : converters) {System.out.println(messageConverter);}}Overridepublic void configureMessageConverters(ListHttpMessageConverter? converters) {FastJsonHttpMessageConverter fastConverter new FastJsonHttpMessageConverter();FastJsonConfig fastJsonConfig new FastJsonConfig();fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat,SerializerFeature.DisableCircularReferenceDetect,SerializerFeature.WriteBigDecimalAsPlain,SerializerFeature.WriteMapNullValue);fastConverter.setFastJsonConfig(fastJsonConfig);ListMediaType supportedMediaTypes new ArrayList();supportedMediaTypes.add(MediaType.APPLICATION_JSON);fastConverter.setSupportedMediaTypes(supportedMediaTypes);converters.add(fastConverter);} }org.springframework.http.converter.ByteArrayHttpMessageConverter71f29d91 org.springframework.http.converter.StringHttpMessageConverter6785df10 org.springframework.http.converter.StringHttpMessageConverter6143b2b1 org.springframework.http.converter.ResourceHttpMessageConvertera63643e org.springframework.http.converter.ResourceRegionHttpMessageConverter43294e9b org.springframework.http.converter.xml.SourceHttpMessageConverter26d24d7a org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter5a78b52b org.springframework.http.converter.json.MappingJackson2HttpMessageConverter144440f5 org.springframework.http.converter.json.MappingJackson2HttpMessageConverter4bab78ce org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter42ffbab6 com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter7672960e 注意 1、可以两种方式同时使用这样可以达到目的在转换器列表的头尾都会出现FastJsonHttpMessageConverter com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter2c5708e7 org.springframework.http.converter.ByteArrayHttpMessageConverter4ffa078d org.springframework.http.converter.StringHttpMessageConverter4e26564d org.springframework.http.converter.ResourceHttpMessageConverter42238078 org.springframework.http.converter.ResourceRegionHttpMessageConverter5627b8eb org.springframework.http.converter.xml.SourceHttpMessageConverter49fe0bcd org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter3516b881 org.springframework.http.converter.json.MappingJackson2HttpMessageConverter6be8ce1b org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConvertere3c36d com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter397a10df   2、不要乱加 EnableWebMvc标签这个标签会导致添加自定义消息转换器失败。因为时间问题目前还不清楚具体原因 针对方案一启动类或任意配置类加了EnableWebMvc后导致自定义的转换器没有出现在集合内即添加自定义转换器失败 package com.gaoshan.verification.config;import org.springframework.context.annotation.Configuration; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;import java.util.List;Configuration EnableWebMvc public class WebMvcConfigurerConfig implements WebMvcConfigurer {Overridepublic void extendMessageConverters(ListHttpMessageConverter? converters) {for (HttpMessageConverter? messageConverter : converters) {System.out.println(messageConverter);}} }package com.gaoshan.verification.config;import com.alibaba.fastjson.serializer.SerializerFeature; import com.alibaba.fastjson.support.config.FastJsonConfig; import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; import org.springframework.boot.autoconfigure.http.HttpMessageConverters; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.MediaType;import java.util.ArrayList; import java.util.List;Configuration public class MessageConvertConfig {Beanpublic HttpMessageConverters fastJsonHttpMessageConverters() {FastJsonHttpMessageConverter fastConverter new FastJsonHttpMessageConverter();FastJsonConfig fastJsonConfig new FastJsonConfig();fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat,SerializerFeature.DisableCircularReferenceDetect,SerializerFeature.WriteBigDecimalAsPlain,SerializerFeature.WriteMapNullValue);fastConverter.setFastJsonConfig(fastJsonConfig);ListMediaType supportedMediaTypes new ArrayList();supportedMediaTypes.add(MediaType.APPLICATION_JSON);fastConverter.setSupportedMediaTypes(supportedMediaTypes);return new HttpMessageConverters(fastConverter);} }org.springframework.http.converter.ByteArrayHttpMessageConverter42238078 org.springframework.http.converter.StringHttpMessageConverter5627b8eb org.springframework.http.converter.ResourceHttpMessageConverter49fe0bcd org.springframework.http.converter.ResourceRegionHttpMessageConverter3516b881 org.springframework.http.converter.xml.SourceHttpMessageConverter6be8ce1b org.springframework.http.converter.support.AllEncompassingFormHttpMessageConvertere3c36d org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter397a10df org.springframework.http.converter.json.MappingJackson2HttpMessageConverter39a865c1 针对方案二启动类或任意配置类加了EnableWebMvc后导致集合内仅有自定义转换器 package com.gaoshan.verification.config;import com.alibaba.fastjson.serializer.SerializerFeature; import com.alibaba.fastjson.support.config.FastJsonConfig; import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; import org.springframework.context.annotation.Configuration; import org.springframework.http.MediaType; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;import java.util.ArrayList; import java.util.List;Configuration EnableWebMvc public class WebMvcConfigurerConfig implements WebMvcConfigurer {Overridepublic void extendMessageConverters(ListHttpMessageConverter? converters) {for (HttpMessageConverter? messageConverter : converters) {System.out.println(messageConverter);}}Overridepublic void configureMessageConverters(ListHttpMessageConverter? converters) {FastJsonHttpMessageConverter fastConverter new FastJsonHttpMessageConverter();FastJsonConfig fastJsonConfig new FastJsonConfig();fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat,SerializerFeature.DisableCircularReferenceDetect,SerializerFeature.WriteBigDecimalAsPlain,SerializerFeature.WriteMapNullValue);fastConverter.setFastJsonConfig(fastJsonConfig);ListMediaType supportedMediaTypes new ArrayList();supportedMediaTypes.add(MediaType.APPLICATION_JSON);fastConverter.setSupportedMediaTypes(supportedMediaTypes);converters.add(fastConverter);} }com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter1df06ecd 启动类代码 package com;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;SpringBootApplication public class VerificationApplication {public static void main(String[] args) {SpringApplication.run(VerificationApplication.class, args);}}
http://www.huolong8.cn/news/70454/

相关文章:

  • 什么网站做装修公司广告比较好画册排版设计网站
  • 网站建设要多久广州网络推广公司电话
  • 潍坊建网站的西安网站建设建站系统
  • 为什么网站显示建设中wordpress太臃肿
  • 丰台企业网站建设泰安网站建设总结
  • 做枪网站北京海淀中关村找工作网站
  • 建网站需要什么手续做招商类型的网站
  • phpcms套好的网站 放到空间上 后台打开的验证码不能显示普通人怎么样做网站
  • 网站模板开发主要作用wordpress 用户评分
  • 怎么建设自己网站的后台徐州建站网站模板
  • 衡阳公司做网站百度推广网页版
  • 做学校网站用什么模版seo首页优化
  • ps专门做兼职的网站有哪些宁德时代网站哪个公司做的
  • 网站图片代码怎么做阿里巴巴每平每屋设计家官网
  • vs网站开发杭州旅游团购网站建设
  • 南宁免费自助建站模板珠海市 网站建设
  • 建网站与建网页的区别汕头网页网站制作
  • 网站策划书模板范文网站建设进展报告
  • 网站空间过期网络科技有限公司 网站建设
  • 网站设计公司模板下载网站百度推广方案
  • 宁德网站设计做网站交付标准
  • 电商网站有哪些特色商城类网站建设
  • 互联网站源码安徽建设项目建设工程在线
  • 广告网站留电话不用验证码wordpress注册跳过邮箱验证
  • 做网站客户一般会问什么问题做pc端网站精英
  • 网站建设方案格式整个网站的关键词
  • 南宁网站推广哪家好网站建设得花多少钱
  • 网站优化方案和实施自学移动端网站开发
  • 网站建设简单流程图用jsp做网站怎么分区
  • wpf可以应用于网站开发吗wordpress轻社区