解决SpringBoot返回结果如果为null或空值不显示处理问题
时间:2022-09-14 09:15:18|栏目: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
springboot传参合和反参时值为null的处理
@JsonIgnoreProperties(ignoreUnknown = true) //忽略传参时其他无用字段
@JsonInclude(JsonInclude.Include.NON_NULL) // 忽略反参时值为null的字段
public class BaseAreaBO implements Serializable {
@ApiModelProperty(value = "地区code")
private String areaCode;
}
上一篇:maven仓库中心mirrors配置多个下载中心(执行最快的镜像)
栏 目:JAVA代码
下一篇:Spring @Cacheable注解类内部调用失效的解决方案
本文标题:解决SpringBoot返回结果如果为null或空值不显示处理问题
本文地址:http://www.codeinn.net/misctech/213640.html






