List<MainDataMd0006PO> listpo = BeanUtils.transferList(mainDataMd0006Params, MainDataMd0006PO.class); //查询 存在的--根据批次编码 List<MainDataMd0006PO> listup = mainDataMd0006Service.selectBatchIds(listpo); // 交集 (list1 & list2) 取list1 表的数据 List<MainDataMd0006PO> listupdate = listpo.stream().filter(item -> listup.stream().map(up -> up.getPOSID()).collect( Collectors.toList()).contains(item.getPOSID())).collect(Collectors.toList()); listupdate.stream().forEach(update -> listup.stream().filter(up -> Objects.equals(update.getPOSID(), up.getPOSID())). findAny().ifPresent(up -> update.setId(up.getId()))); // 差集 (list1 - list2) List<MainDataMd0006PO> listadd = listpo.stream().filter(item -> !listup.stream().map(up -> up.getPOSID()).collect( Collectors.toList()).contains(item.getPOSID())).collect(Collectors.toList());