先查数据库获取关于名字字段list
List<String> nameList = this.baseMapper
.selectList(new LambdaQueryWrapper<TCorp>().select(TCorp::getTcName))
.stream()
.map(name -> name.getTcName())
.collect(Collectors.toList());
根据名字字段list值筛选出另一个list中名字相等的数据
List<TCorp> newCorpList = list.stream()
.filter(corp -> nameList.contains(corp.getTcName()))
.collect(Collectors.toList());
完整代码
public List<TCorp> getUpdateCorpList(List<TCorp> list){
List<String> nameList = this.baseMapper.selectList(new LambdaQueryWrapper<TCorp>().select(TCorp::getTcName))
.stream()
.map(name -> name.getTcName())
.collect(Collectors.toList());
List<TCorp> newCorpList = list.stream()
.filter(corp -> nameList.contains(corp.getTcName()))
.collect(Collectors.toList());
return newCorpList;
}