本文主要是介绍上移下移操作,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
很想弄个上移下移操作的通用层,但是在设计的时候发现设计后整个Action代码用起来却更加的复杂。所以就先放弃掉,以后有更好的办法再将其设计一遍。现在先只能将我所写的Action粘贴过来,以后如果碰见上移下移的操作方便参照,下面的这个需要对照以前设计的通用层:
public String operateClassification(){Classification theClassification = new Classification();//artId字段倒序方式查找整个Classification中的数据List allList = userService.selete(null,null, "desc","Classification","artId");//nextId是从jsp传过来的用来标识是上移还是下移操作,下面这个是上移操作if(nextId==0){for(int i =0;i<allList.size();i++){Classification theClassification1 = (Classification)allList.get(i);Integer id2 = theClassification1.getArtId();if(id==id2){System.out.println(id);//上一条记录Classification theClassification2 = (Classification)allList.get(i-1);int upId = theClassification2.getArtId();String id3 = String.valueOf(theClassification2.getId());String upID = String.valueOf(upId);//当前artId,idint onId = theClassification1.getArtId();String id4 = String.valueOf(theClassification1.getId());String onID = String.valueOf(onId);String[] array3={"ArtId"};Integer[] array4 = {upId};Integer[] array5 ={onId};//靠id来查询记录然后彼此调换artId的值userService.edit(theClassification, "id", id3, "Classification", null, null, array3, array5, null, null);userService.edit(theClassification, "id", id4, "Classification", null, null, array3, array4, null, null);break;}}}else{for(int i =0;i<allList.size();i++){Classification theClassification1 = (Classification)allList.get(i);int id2 = theClassification1.getArtId();if(id==id2&i<allList.size()-1){System.out.println(id+"aa");Classification theClassification2 = (Classification)allList.get(i+1);int upId = theClassification2.getArtId();String id3 = String.valueOf(theClassification2.getId());String upID = String.valueOf(upId);int onId = theClassification1.getArtId();String id4 = String.valueOf(theClassification1.getId());String onID = String.valueOf(onId);String[] array3={"ArtId"};Integer[] array4 = {upId};Integer[] array5 ={onId};userService.edit(theClassification, "id", id3, "Classification", null, null, array3, array5, null, null);userService.edit(theClassification, "id", id4, "Classification", null, null, array3, array4, null, null);//break很关键,漏了很可能出错break;}}}return "operateClassification";}
这篇关于上移下移操作的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!