springboot中用fastjson處理返回值為null的屬性值
我們先來看代碼:
@Configurationpublic class WebMvcConfig extends WebMvcConfigurationSupport { public FastJsonHttpMessageConverter fastJsonHttpMessageConverter() { FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig = new FastJsonConfig(); //todo 這里進(jìn)行配置,空和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; }}
配置上這個(gè)可以在返回的信息中,假如說有null字段的時(shí)候,前端不會進(jìn)行顯示這種信息
知識點(diǎn)擴(kuò)展:
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的注解,比如

到此這篇關(guān)于springboot中用fastjson處理返回值為null的屬性值的文章就介紹到這了,更多相關(guān)springboot中用fastjson處理返回值問題詳解內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. Python 制作查詢商品歷史價(jià)格的小工具2. python 使用事件對象asyncio.Event來同步協(xié)程的操作3. ASP基礎(chǔ)知識VBScript基本元素講解4. Python sublime安裝及配置過程詳解5. ASP.NET MVC使用jQuery ui的progressbar實(shí)現(xiàn)進(jìn)度條6. Python3 json模塊之編碼解碼方法講解7. Python 合并拼接字符串的方法8. Python 利用Entrez庫篩選下載PubMed文獻(xiàn)摘要的示例9. Linux刪除系統(tǒng)自帶版本Python過程詳解10. 使用Python webdriver圖書館搶座自動預(yù)約的正確方法

網(wǎng)公網(wǎng)安備