1. 程式人生 > >練習:將值是null的數據刪除掉(剔除):com.fasterxml.jackson.annotation.JsonInclude;包

練習:將值是null的數據刪除掉(剔除):com.fasterxml.jackson.annotation.JsonInclude;包

not ann fas 輸出格式 reat integer mes 金額 clu

練習:將值是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;包