适用于向数据库新增时名称重复的场景,此时 public void addProgram(ProgramVO program){ List nameList = programService.getProgramNameList(program.getUserId(),program.getAlbumId()); int num = 1; String newName = this.getNewNa
public void addProgram(ProgramVO program){ ListnameList = programService.getProgramNameList(program.getUserId(),program.getAlbumId()); int num = 1; String newName = this.getNewName(nameList,num,program.getProgramName); program.setProgramName(newName); programService.addProgram(program); } //判重,如果重名给个新名 private String getNewName(List nameList, int num, String oldName) { if (programNameList.contains(oldName)) { newName = oldName + num; a++; newName = getNewName(programNameList, a, newName); } return pName; }