解决SpringBoot返回结果如果为null或空值不显示处理问题
更新时间:2021年07月28日 11:47:25 作者:孤独二世
这篇文章主要介绍了解决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使用DynamicDataSource动态切换数据源的实现过程
这篇文章主要给大家介绍了关于springboot使用DynamicDataSource动态切换数据源的实现过程,Spring Boot应用中可以配置多个数据源,并根据注解灵活指定当前使用的数据源,需要的朋友可以参考下2023-08-08SpringBoot Controller Post接口单元测试示例
今天小编就为大家分享一篇关于SpringBoot Controller Post接口单元测试示例,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧2018-12-12
最新评论