java排序id乱问题求大神解决爱你。 我是根据movesort来排序的,如果我的movesort是13579的话 就排序不了了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 需求就是为什么1234的话我可以随意上下移动,。 但是13579就不行,移动不了 @Override public int updateSort(String notepadId, String moveSort) { ATextNotepad notePad = this.getNotePadById(Long.valueOf(notepadId)); //得到该记录的sort long sort = notePad.getMovesort().longValue(); long sort1; if("0" == moveSort || moveSort.equals("0")){//向上 sort1 = sort - 1; }else{ sort1 = sort + 1; } List list = this.notepaddao.getNotePadList("from ATextNotepad t where t.movesort="+sort1) ; if(list.size()>0){ ATextNotepad notePad1 = (ATextNotepad) list.get(0); Long s1 = notePad1.getMovesort(); Long s2 = notePad.getMovesort(); notePad.setMovesort(s1); notePad1.setMovesort(s2); this.notepaddao.updateNotePad(notePad); this.notepaddao.updateNotePad(notePad1); } return 0; } 找前一个的算法是 movesort 小于当前movesort的第一个结果。你非要自己定义movesort -1去按 movesort 查询当然找不到 我只是来混个每日10分的, 参考下这个下面的其他回答: https://zhidao.baidu.com/question/574533221.html @Overridepublic int updateSort(String notepadId, String moveSort) {ATextNotepad notePad = this.getNotePadById(Long.valueOf(notepadId));//得到该记录的sortlong sort = notePad.getMovesort().longValue();String sql="";if("0" == moveSort || moveSort.equals("0")){//向上sql="t.movesort<sort order by t.movesort DESC";}else{sql="t.movesort>sort order by t.movesort ";}List list = this.notepaddao.getNotePadList("from ATextNotepad t where "+sql+" LIMIT 0,1") ;if(list.size()>0){ATextNotepad notePad1 = (ATextNotepad) list.get(0);Long s1 = notePad1.getMovesort();Long s2 = notePad.getMovesort();notePad.setMovesort(s1);notePad1.setMovesort(s2);this.notepaddao.updateNotePad(notePad);this.notepaddao.updateNotePad(notePad1);}return 0;} if("0" == moveSort || moveSort.equals("0")){//向上改为if(moveSort != null && "0".equals(moveSort)){//向上第一: "0" == moveSort 字符串不能用 == 来判断,要用 equals 来比较;第二:moveSort.equals("0") 要把"0" 放到equals前面 "0".equals(moveSort) ,这样moveSort为空的时候也不会报错,如果moveSort为空会报错; struts2+jxl怎么才能导出多个excel文件?求帮助 hibernate一对多双向关联时删除的问题? dao层或者Service层,设为static可以吗? 二进制文件处理的问题 通过filter判断用户权限的问题 about callback in jQuery?? struts2标签 页面显示问题? ECLIPSE问题! axis配置有问题,求救 用人用过turbine或者torque吗,(分不够再加,担心没人知道,只给10分) 做MVC测试的时候报错,大手掌掌眼 java排序id乱问题求大神解决爱你。
需求就是为什么1234的话我可以随意上下移动,。 但是13579就不行,移动不了 @Override
public int updateSort(String notepadId, String moveSort) {
ATextNotepad notePad = this.getNotePadById(Long.valueOf(notepadId));
//得到该记录的sort
long sort = notePad.getMovesort().longValue();
long sort1;
if("0" == moveSort || moveSort.equals("0")){//向上
sort1 = sort - 1;
}else{
sort1 = sort + 1;
}
List list = this.notepaddao.getNotePadList("from ATextNotepad t where t.movesort="+sort1) ;
if(list.size()>0){
ATextNotepad notePad1 = (ATextNotepad) list.get(0);
Long s1 = notePad1.getMovesort();
Long s2 = notePad.getMovesort();
notePad.setMovesort(s1);
notePad1.setMovesort(s2);
this.notepaddao.updateNotePad(notePad);
this.notepaddao.updateNotePad(notePad1);
}
return 0;
}
参考下这个下面的其他回答: https://zhidao.baidu.com/question/574533221.html
public int updateSort(String notepadId, String moveSort) {
ATextNotepad notePad = this.getNotePadById(Long.valueOf(notepadId));
//得到该记录的sort
long sort = notePad.getMovesort().longValue();
String sql="";
if("0" == moveSort || moveSort.equals("0")){//向上
sql="t.movesort<sort order by t.movesort DESC";
}else{
sql="t.movesort>sort order by t.movesort ";
}
List list = this.notepaddao.getNotePadList("from ATextNotepad t where "+sql+" LIMIT 0,1") ;
if(list.size()>0){
ATextNotepad notePad1 = (ATextNotepad) list.get(0);
Long s1 = notePad1.getMovesort();
Long s2 = notePad.getMovesort();
notePad.setMovesort(s1);
notePad1.setMovesort(s2);
this.notepaddao.updateNotePad(notePad);
this.notepaddao.updateNotePad(notePad1);
}
return 0;
}
改为
if(moveSort != null && "0".equals(moveSort)){//向上第一: "0" == moveSort 字符串不能用 == 来判断,要用 equals 来比较;
第二:moveSort.equals("0") 要把"0" 放到equals前面 "0".equals(moveSort) ,这样moveSort为空的时候也不会报错,如果moveSort为空会报错;