SpringBoot返回结果为null或空值不显示处理方法


方法一:自定义消息转换器

 

@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter{
    /**
     * 利用fastjson替换掉jackson
     * @param converters
     */
    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        super.configureMessageConverters(converters);
        FastJsonConfig fastJsonConfig = new FastJsonConfig();
        fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
    }
}

 

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

spring:
  jackson:
    default-property-inclusion: non_null

方法三:单DTO空值过滤,DTO上添加如下注解

@JsonInclude(JsonInclude.Include.NON_EMPTY)    
@JsonInclude(JsonInclude.Include.NON_NULL)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM