久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

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

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

瀏覽:24日期: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
相關文章:
主站蜘蛛池模板: 南丹县| 蒙城县| 象州县| 屏东县| 长葛市| 布拖县| 松原市| 涡阳县| 玉树县| 汕尾市| 政和县| 淮滨县| 象山县| 巴中市| 萍乡市| 梁平县| 南安市| 巫山县| 黔西县| 怀柔区| 襄樊市| 沅陵县| 中西区| 武威市| 专栏| 宝清县| 博白县| 泸州市| 汾西县| 侯马市| 高尔夫| 湟源县| 黄大仙区| 石家庄市| 阿荣旗| 织金县| 池州市| 毕节市| 七台河市| 临高县| 淳安县|