使⽤Lambda转换集合数据⾄新集合1. 测试
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.JSON(args2) + " - ".substring(0,1)));
// TODO: {"name":"靳露","id":1} {"name":"于瑶","id":2} {"name":"王莹","id":4}
}
2. ⽅法
static List<Student01> buildDtoList(List<Student01> stuList) {
return stuList.stream().map(aItem -> {
Student01 student01 = new Student01();
student01.Id());
student01.Name());
return student01;
}).List());
}
3. 对象转对象⽰例
private RcvSubmitParamBo buildRcvSubmitBoParam(BaseRequest<SubmitRcvParamDto> request) {
RcvSubmitParamBo rcvSubmitParamBo = new RcvSubmitParamBo();
rcvSubmitParamBo.Data().getAsnNo());
rcvSubmitParamBo.Data().getWarehouseId());
rcvSubmitParamBo.Pin());
rcvSubmitParamBo.TenantId());
rcvSubmitParamBo.Data().getSubmitRcvSkuDtos().stream().map(aItem -> {
SubmitRcvSkuBo submitRcvSkuBo = new SubmitRcvSkuBo();
submitRcvSkuBo.ExpireDate());
submitRcvSkuBo.LocId());
submitRcvSkuBo.ProduceDate());
submitRcvSkuBo.Qty());
submitRcvSkuBo.SkuId());
submitRcvSkuBo.SkuNature());
submitRcvSkuBo.SkuType());
return submitRcvSkuBo;
}).List()));
return rcvSubmitParamBo;
}
4. 集合转集合⽰例
private List<RcvStockInfoSo> asnDetail2RcvStockSo(List<AsnDetailDTO> asnDetailList) {
return asnDetailList.stream().map(aItem -> {
RcvStockInfoSo rcvStockInfoSo = new RcvStockInfoSo();
rcvStockInfoSo.AsnHeaderNo());
rcvStockInfoSo.AsnRefNo());
rcvStockInfoSo.CreateDate());
rcvStockInfoSo.ActualQty());
rcvStockInfoSo.ExpectedQty());
rcvStockInfoSo.ExtSkuId());
nodejs字符串转数组rcvStockInfoSo.LineStatus());
rcvStockInfoSo.PurchasePrice());
rcvStockInfoSo.SaleMode());
rcvStockInfoSo.SaleUnit());
rcvStockInfoSo.ShelfLife());
rcvStockInfoSo.SkuId());
rcvStockInfoSo.SkuModelNo());
rcvStockInfoSo.SkuName());
rcvStockInfoSo.SkuOrderNo());
rcvStockInfoSo.SkuType());
rcvStockInfoSo.TenantId());
rcvStockInfoSo.Uom());
rcvStockInfoSo.UpcCodes());
rcvStockInfoSo.WarehouseId());
return rcvStockInfoSo;
}).List());
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论