解决SpringBoot返回结果如果为null或空值不显示处理问题

网友投稿 1144 2022-12-24

解决SpringBoot返回结果如果为null或空值不显示处理问题

解决SpringBoot返回结果如果为null或空值不显示处理问题

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

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

@Configuration

public class WebMvcConfig extends WebMvcConfigurerAdapter{

// /**

// * 利用fastjson替换掉jackson

// * @param converters

// */

@Override

public void configureMessageConverters(List> 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 Serihttp://alizable {

@ApiModelProperty(value = "地区code")

private String areaCode;

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:智能车载终端休眠功能(车载智能监控终端系统作用)
下一篇:智能车载终端行业研究(智能车载终端行业研究现状)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~