- 测试
public static void main(String[] args) {
// 将 pojoList 转换至 dtoList 中
List<Student01> dtoList = new ArrayList<>();
List<Student01> pojoList = new ArrayList<>();
Collections.addAll(pojoList, new Student01(1, "靳露"), new Student01(2, "于瑶"), new Student01(4, "王莹"));
buildDtoList(pojoList).forEach(args1 -> dtoList.add(args1));
dtoList.forEach(args2 -> System.out.print(JSON.toJSON(args2) + " - ".substring(0,1)));
// TODO: {"name":"靳露","id":1} {"name":"于瑶","id":2} {"name":"王莹","id":4}
}
- 方法
static List<Student01> buildDtoList(List<Student01> stuList) {
return stuList.stream().map(aItem -> {
Student01 student01 = new Student01();
student01.setId(aItem.getId());
student01.setName(aItem.getName());
return student01;
}).collect(Collectors.toList());
}
- 对象转对象示例
private RcvSubmitParamBo buildRcvSubmitBoParam(BaseRequest<SubmitRcvParamDto> request) {
RcvSubmitParamBo rcvSubmitParamBo = new RcvSubmitParamBo();
rcvSubmitParamBo.setAsnNo(request.getData().getAsnNo());
rcvSubmitParamBo.setWarehouseId(request.getData().getWarehouseId());
rcvSubmitParamBo.setOperator(request.getPin());
rcvSubmitParamBo.setTenantId(request.getTenantId());
rcvSubmitParamBo.setSubmitRcvSkuBos(request.getData().getSubmitRcvSkuDtos().stream().map(aItem -> {
SubmitRcvSkuBo submitRcvSkuBo = new SubmitRcvSkuBo();
submitRcvSkuBo.setExpireDate(aItem.getExpireDate());
submitRcvSkuBo.setLocId(aItem.getLocId());
submitRcvSkuBo.setProduceDate(aItem.getProduceDate());
submitRcvSkuBo.setQty(aItem.getQty());
submitRcvSkuBo.setSkuId(aItem.getSkuId());
submitRcvSkuBo.setSkuNature(aItem.getSkuNature());
submitRcvSkuBo.setSkuType(aItem.getSkuType());
return submitRcvSkuBo;
}).collect(Collectors.toList()));
return rcvSubmitParamBo;
}
- 集合转集合示例
private List<RcvStockInfoSo> asnDetail2RcvStockSo(List<AsnDetailDTO> asnDetailList) {
return asnDetailList.stream().map(aItem -> {
RcvStockInfoSo rcvStockInfoSo = new RcvStockInfoSo();
rcvStockInfoSo.setAsnHeaderNo(aItem.getAsnHeaderNo());
rcvStockInfoSo.setAsnRefNo(aItem.getAsnRefNo());
rcvStockInfoSo.setCreateDate(aItem.getCreateDate());
rcvStockInfoSo.setActualQty(aItem.getActualQty());
rcvStockInfoSo.setExpectedQty(aItem.getExpectedQty());
rcvStockInfoSo.setExtSkuId(aItem.getExtSkuId());
rcvStockInfoSo.setLineStatus(aItem.getLineStatus());
rcvStockInfoSo.setPurchasePrice(aItem.getPurchasePrice());
rcvStockInfoSo.setSaleMode(aItem.getSaleMode());
rcvStockInfoSo.setSaleUnit(aItem.getSaleUnit());
rcvStockInfoSo.setShelfLife(aItem.getShelfLife());
rcvStockInfoSo.setSkuId(aItem.getSkuId());
rcvStockInfoSo.setSkuModelNo(aItem.getSkuModelNo());
rcvStockInfoSo.setSkuName(aItem.getSkuName());
rcvStockInfoSo.setSkuOrderNo(aItem.getSkuOrderNo());
rcvStockInfoSo.setSkuType(aItem.getSkuType());
rcvStockInfoSo.setTenantId(aItem.getTenantId());
rcvStockInfoSo.setUom(aItem.getUom());
rcvStockInfoSo.setUpcCodes(aItem.getUpcCodes());
rcvStockInfoSo.setWarehouseId(aItem.getWarehouseId());
return rcvStockInfoSo;
}).collect(Collectors.toList());
}