数据库表对应的字段status,当上移时当前记录status-1,status-1条记录+1,值互换,status为12345的记录,假如status为23的记录被删除;现在上移status为4的记录
数据库 表对应的字段 status,当上移时 当前记录status-1,status-1条记录+1,值互换,
status 为 1 2 3 4 5 的记录,假如 status为2 3的记录被删除;现在上移status为4的记录
上移
下移
action=“/my/upORdown!upORdown.action?ids=${status}&oneId=“upORdown”;//此处的upORdown不能这样赋值给oneId (说明:使用js赋值)
当前的status值 由页面action带到后台 假设带的参数命名为ids,
public void upORdown(){
Integer ids=0;
Integer oneId=0;//用于判断执行上移还是下移
//get和set方法省略
if(this.getOneId==1){
///上移:
for(i=this.getIds();i=
//需要先查询在使用
{
aOBJ=this.service.selectBystatus(this.getIds());//查询由action带到后台值为status的记录
bOBJ=this.service.selectBystaus(i- -);//查询status为i- -对象是否存在;
if( bOBJ!=null&& Integer a= bOBJ.getStatus()){
this.getIds()=a;//将status值为i- -赋给当前的status; 将上一条和下一条的status值互换
this.service.aOBJupdateById( Integer.parse(aOBJ.getId()) , a );//根据aId更新aOBJ对象的status
Integer b=this.getIds();//将aOBJ对象的status值赋给bOBJ对象的status,将上一条和下一条的status值互换
this.service.update(bOBJ.getId(),b)//更新bOBJ对象的status
list=this.service.selectAllBystatus();//重新查一遍数据,根据status升序查找
}
}else if(this.getOneId==2){
//下移 status 为 1 2 3 4 5 的记录,假如 status为2 3的记录被删除;现在下移status为1的记录
for(i=this.getIds();i=
aOBJ=this.service.selectBystatus(this.getIds());//查询由action带到后台值为status的记录
bOBJ=this.service.selectBystaus(i++);//查询status为i++对象是否存在;
if( bOBJ!=null&&Integer a=bOBJ.getStatus()){
this.status=a;// 将bOBJ对象status值赋给aOBJ对象的status; 将上一条和下一条的status值互换
this.service.aOBJupdateById( Integer.parse(aOBJ.getId()) , a);//根据aOBJ的id更新自己的status
Integer b=aOBJ.getStatus();//将aOBJ对象的status值赋给bOBJ对象的status,将上一条和下一条的status值互换
this.service.bOBJupdateById(bOBJ.getId(),b)//更新bOBJ对象的status
list=this.service.selectAllBystatus();//重新查一遍数据,根据status升序查找
}
}
展开