使用递归实现删除
1 //删除 2 public String dictionaryDel(){ 3 try { 4 if (ids != null && !"".equals(ids)) { 5 6 String[] split = ids.split(","); 7 8 for(String id:split){ 9 utilService.updateAll("update Dictionary d set d.isDele=1 where d.id="+id); 10 dictionarySet(id); 11 } 12 for(String id:split){ 13 Dictionary dictionaryOld = (Dictionary) this.utilService.getObjectById(Dictionary.class, Integer.parseInt(id)); 14 if(dictionaryOld.getFkDicId()!=0){ 15 int count=utilService.getHqlCount("from Dictionary d where d.isDele=0 and d.fkDicId="+dictionaryOld.getFkDicId()); 16 if(count==0){ 17 Dictionary dictionaryP = (Dictionary) this.utilService.getObjectById(Dictionary.class, dictionaryOld.getFkDicId()); 18 dictionaryP.setIsLeaf(1); 19 utilService.update(dictionaryP); 20 } 21 } 22 } 23 } 24 return dictionaryList(); 25 } catch (Exception e) { 26 e.printStackTrace(); 27 } 28 return ERROR; 29 } 30 private void dictionarySet(String id)throws Exception { 31 List<Dictionary> dictionaries=(List<Dictionary>) utilService.getHqlAll("from Dictionary d where d.isDele=0 and d.fkDicId="+id); 32 if(dictionaries!=null&&dictionaries.size()>0){ 33 for(Dictionary dictionary:dictionaries){ 34 utilService.updateAll("update Dictionary d set d.isDele=1 where d.id="+dictionary.getId()); 35 dictionarySet(dictionary.getId().toString()); 36 } 37 } 38 }
数据库