好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

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

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

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

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

@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配置文件中

?

1

2

3

spring:

   jackson:

     default -property-inclusion: non_null

springboot传参合和反参时值为null的处理

?

1

2

3

4

5

6

@JsonIgnoreProperties (ignoreUnknown = true )   //忽略传参时其他无用字段

@JsonInclude (JsonInclude.Include.NON_NULL)   // 忽略反参时值为null的字段

public class BaseAreaBO implements Serializable {

     @ApiModelProperty (value = "地区code" )

     private String areaCode;

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。

原文链接:https://HdhCmsTestcnblogs测试数据/guduershi/p/10531523.html

查看更多关于解决SpringBoot返回结果如果为null或空值不显示处理问题的详细内容...

  阅读:11次