[代码解析005] 关于一次bug排查解析 | new出一个对象其属性默认值是?
0、问题描述
子单据更新操作,单据状态更新,更新后单号变为0,经过排查发现更新操作代码中int类型单据号字段更新时未设置值。
1、代码片段
private int rowNum;
// 子单据状态更新
List<OutboundOrderDetails> updateOutboundOrderDetailsList = Lists.newArrayList();
outboundOrderDetailsList.forEach(val -> {
OutboundOrderDetails updateEntity = new OutboundDetailVO();
updateEntity.setId(val.getId());
updateEntity.setStatus(OutboundOrderDetails.STATUS_LOCK);
updateEntity.preUpdate();
updateOutboundOrderDetailsList.add(updateEntity);
});
outboundOrderDetailsService.updateBatchById(updateOutboundOrderDetailsList);
新增 updateEntity.setRowNum(val.getRowNum());
// 子单据状态更新
List<OutboundOrderDetails> updateOutboundOrderDetailsList = Lists.newArrayList();
outboundOrderDetailsList.forEach(val -> {
OutboundOrderDetails updateEntity = new OutboundDetailVO();
updateEntity.setId(val.getId());
updateEntity.setStatus(OutboundOrderDetails.STATUS_LOCK);
updateEntity.setRowNum(val.getRowNum());
updateEntity.preUpdate();
updateOutboundOrderDetailsList.add(updateEntity);
});
outboundOrderDetailsService.updateBatchById(updateOutboundOrderDetailsList);
2、涉及知识点
Java基础,int类型默认值为0