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