码迷,mamicode.com
首页 > Web开发 > 详细

练习:将值是null的数据删除掉(剔除):com.fasterxml.jackson.annotation.JsonInclude;包

时间:2018-11-21 19:36:22      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:ota   展示   timestamp   默认   detail   csharp   支付   phone   get   

练习:将值是null的数据删除掉(剔除):com.fasterxml.jackson.annotation.JsonInclude;包

例如,有数据是null,不想展示

{
  "statusCode": 0,
  "message": "返回成功",
  "data": [{
    "orderId": "1542785381425923730",
    "buyerName": "王五",
    "buyerPhone": "15605852476",
    "buyerAddr": "北京王府井",
    "buyerOpenid": "110112",
    "buyerAmount": 4.40,
    "orderStatus": 0,
    "payStatus": 0,
    "createTimestamp": 1542794276000,
    "updateTimestamp": 1542794276000,
    "orderDetailList": null
  }]
}

  

 

解决方法:

在输出格式的entity/vo/dto添加com.fasterxml.jackson.annotation.JsonInclude;包的注解

@JsonInclude(JsonInclude.Include.NON_NULL)
/**订单*/
@Data //get/set
//将值是null的数据剔除
@JsonInclude(JsonInclude.Include.NON_NULL)
public class OrderDTO {

    private String orderId;

    /**买家名字**/
    private String buyerName;

    /**买家手机**/
    private String buyerPhone;

    /**买家地址**/
    private String buyerAddr;

    /**用户openid**/
    private String buyerOpenid;

    /**订单金额**/
    private BigDecimal buyerAmount;

    /**订单状态, 默认状态0新订单**/
    private Integer orderStatus;

    /**支付状态, 默认状态0等待支付**/
    private Integer payStatus;

    private Date createTimestamp;

    private Date updateTimestamp;

    List<OrderDetail> orderDetailList;

}

  

练习:将值是null的数据删除掉(剔除):com.fasterxml.jackson.annotation.JsonInclude;包

标签:ota   展示   timestamp   默认   detail   csharp   支付   phone   get   

原文地址:https://www.cnblogs.com/achengmu/p/9996831.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!