SpringBoot返回結果如果為null或空值不顯示處理方法


第一種方法:自定義消息轉換器

 1 @Configuration
 2 public class WebMvcConfig extends WebMvcConfigurerAdapter{
 3 
 4 
 5     //    /**
 6 //     * 利用fastjson替換掉jackson
 7 //     * @param converters
 8 //     */
 9     @Override
10     public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
11         super.configureMessageConverters(converters);
12         FastJsonConfig fastJsonConfig = new FastJsonConfig();
13         fastJsonConfig.setSerializerFeatures(
14 
15                 SerializerFeature.PrettyFormat
16         );
17 
18 
19     }
20 
21 
22 }
View Code

第二種方法:在application.yml配置文件中

spring:
  jackson:
    default-property-inclusion: non_null

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM