如何解决SpringBoot返回结果如果为null或空值不显示处理问题
这篇文章主要介绍如何解决SpringBoot返回结果如果为null或空值不显示处理问题,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
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
springboot传参合和反参时值为null的处理
@JsonIgnoreProperties(ignoreUnknown = true) //忽略传参时其他无用字段 @JsonInclude(JsonInclude.Include.NON_NULL) // 忽略反参时值为null的字段 public class BaseAreaBO implements Serializable { @ApiModelProperty(value = "地区code") private String areaCode; }
以上是“如何解决SpringBoot返回结果如果为null或空值不显示处理问题”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!