第一种写法
//查询网元列表
List<TResNe> neList = neManager.getNeList();
//网元名称不能重复
if(neList.stream()
.filter(item->item.getName()
.equals(neInfoBO.getName()))
.findAny()
.isPresent()){
throw new ProcessException(ExceptionEnum.NE_NEME_REPEAT_ERROR);
}
第二种写法
//查询网元列表
List<TResNe> neList = neManager.getNeList();
//网元名称不能重复
if(neList.stream()
.anyMatch(item->item.getName()
.equals(neInfoBO.getName()))){
throw new ProcessException(ExceptionEnum.NE_NEME_REPEAT_ERROR);
}
第三种写法
是按照特定的字段查询数据库,看数据库中是否存在这条数据,根据这条数据和传入的数据进行对比,看是否相等。
//根据name查询
List<TResNe> tResNes = neManager.getNesByName(neInfoBO.getName());
if (!CollectionUtils.isEmpty(tResNes)) {
throw new ProcessException(ExceptionEnum.NE_NAME_EXIST_ERROR);
}
//根据链路名称查询链路信息
TResTopolink tResTopolink1 = linkManager.getlinkInfoByName(linkBO.getName());
if(!ObjectUtils.isEmpty(tResTopolink1)){
throw new ProcessException(ExceptionEnum.LINK_NAME_ERROR);
}