国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

springboot中用fastjson處理返回值為null的屬性值

瀏覽:62日期:2023-05-29 17:15:42

我們先來看代碼:

@Configurationpublic class WebMvcConfig extends WebMvcConfigurationSupport { public FastJsonHttpMessageConverter fastJsonHttpMessageConverter() { FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig = new FastJsonConfig(); //todo 這里進行配置,空和null,不返回 fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); SerializeConfig serializeConfig = SerializeConfig.globalInstance; serializeConfig.put(LocalDateTime.class, LocalDateTimeSerializer.instance); fastJsonConfig.setSerializeConfig(serializeConfig); List<MediaType> mediaTypeList = new ArrayList<>(); mediaTypeList.add(MediaType.APPLICATION_JSON_UTF8); mediaTypeList.add(MediaType.APPLICATION_JSON); fastJsonHttpMessageConverter.setSupportedMediaTypes(mediaTypeList); fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig); return fastJsonHttpMessageConverter; }}

配置上這個可以在返回的信息中,假如說有null字段的時候,前端不會進行顯示這種信息

知識點擴展:

springboot中用fastjson處理返回值為null的屬性值

@Bean public HttpMessageConverters fastJsonHttpMessageConverters(){ FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); fastJsonConfig.setDateFormat('yyyy-MM-dd'); fastConverter.setFastJsonConfig(fastJsonConfig); HttpMessageConverter<?> converter = fastConverter; return new HttpMessageConverters(converter); }

然后就可以在返回的DTO中使用fastjson的注解,比如

springboot中用fastjson處理返回值為null的屬性值

到此這篇關于springboot中用fastjson處理返回值為null的屬性值的文章就介紹到這了,更多相關springboot中用fastjson處理返回值問題詳解內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Spring
相關文章:
主站蜘蛛池模板: 许昌县| 久治县| 沙河市| 玛多县| 临澧县| 车险| 合江县| 集贤县| 尉氏县| 广水市| 宁陕县| 达拉特旗| 阿城市| 连城县| 广水市| 柘城县| 和政县| 龙口市| 克什克腾旗| 华亭县| 南陵县| 邵阳市| 闽侯县| 孟村| 丽江市| 彝良县| 曲水县| 华蓥市| 武胜县| 祁连县| 邯郸县| 吉首市| 岳阳市| 吉水县| 原阳县| 江华| 商丘市| 紫金县| 江都市| 德惠市| 镇康县|