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

偏执的太偏执、 2023-09-30 11:41 68阅读 0赞

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

aHR0cHM6Ly9pbWFnZXMuY25ibG9ncy5jb20vT3V0bGluaW5nSW5kaWNhdG9ycy9FeHBhbmRlZEJsb2NrU3RhcnQuZ2lm

复制代码

1 @Configuration
2 public class WebMvcConfig extends WebMvcConfigurerAdapter{
3
4
5 // /**
6 // * 利用fastjson替换掉jackson
7 // * @param converters
8 // */
9 @Override
10 public void configureMessageConverters(List> converters) {
11 super.configureMessageConverters(converters);
12 FastJsonConfig fastJsonConfig = new FastJsonConfig();
13 fastJsonConfig.setSerializerFeatures(
14
15 SerializerFeature.PrettyFormat
16 );
17
18
19 }
20
21
22 }

复制代码

第二种方法:在application.yml配置文件中

spring:
jackson:
default-property-inclusion: non_null

发表评论

表情:
评论列表 (有 0 条评论,68人围观)

还没有评论,来说两句吧...

相关阅读