zoukankan      html  css  js  c++  java
  • 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)
  • 相关阅读:
    设计模式
    工厂方法模式
    简单工厂模式
    tornado自定义Form组件
    tornado
    Tornado框架的知识系列
    Linux基本命令
    day2
    day1
    使用cp复制文件夹却不能打开
  • 原文地址:https://www.cnblogs.com/sunshinekevin/p/12110910.html
Copyright © 2011-2022 走看看