拖動排序的後台處理

2021-08-30 09:32:07 字數 1568 閱讀 2096

有時候總是要用到排序,一下總結了兩種排序的演算法。

(待排序的實體物件有有個序號字段)

1、把一物件排在目標物件之上;可以跨級排序。排序之後目標物件的序號總是排在被排序的物件之後。

// 目標序號

integer intmubiaoxuhao = mubiaoyh.getyhxh();

tyh tyh = tyhdao.findbyid(myh.getyhid());//待排序的物件

string jpql_jia = "update tyh model set model.yhxh = model.yhxh + 1 where model.yhxh >= ? and model.tbmbyyhbmid.classid = " + myh.getyhbmid();

string jpql_jian = "update tyh model set model.yhxh = model.yhxh - 1 where model.yhxh >= ? and model.tbmbyyhbmid.classid = " + tyh.gettbmbyyhbmid().getclassid();

if (intmubiaoxuhao - 1 > tyh.getyhxh() && myh.getyhbmid().equals(tyh.gettbmbyyhbmid().getclassid())) else if (intmubiaoxuhao < tyh.getyhxh() || !myh.getyhbmid().equals(tyh.gettbmbyyhbmid().getclassid())) tyhdao.update(tyh);

我採用的是spring和jap做的,此處只介紹演算法思路。配置就免了。

2、也就是很普通的替換排序,乙個物件替換了另乙個物件的位置,當目標序號》原始序號,小於等於目標序號的物件序號都-1,當目標序號《原始序號,大於等於目標序號的物件序號都+1。**:

integer intmubiaoxuhao = 0;

txx txx = txxdao.findbyid(xxid);

txx txxnew = txxdao.findbyid(xxnewid);//被替換的目標選項

intmubiaoxuhao = txxnew.get***h();//新序號,目標序號

string jpql_jia = "update txx model set model.***h = model.***h + 1 where model.***h >= ? and model.xxlx ='"+txx.getxxlx()+"'";

string jpql_jian = "update txx model set model.***h = model.***h - 1 where model.***h >= ? and model.xxlx ='"+txx.getxxlx()+"'";

if (intmubiaoxuhao > txx.get***h() ) else if (intmubiaoxuhao < txx.get***h())

txx.set***h(intmubiaoxuhao);

txxdao.update(txx);

節點拖動後台處理

require include conn.php require include db conn.php require tree treemenu.php dbconn new db conn tree menu new treemenu conn 託拽型別 drag type post drag...

演算法 拖動排序

選單 菜品排序問題 在菜品分類和菜品表中,新增排序字段,以供使用者排序。新增時需要插入序號 max 1 查詢時按照序號從低到高的順序排序 排序演算法 以菜品為例 牛肉粉 序號1 雞蛋飯 序號2 烤羊肉 序號3 滷豆腐 序號4 現在需要將 滷豆腐 放在第一位 1 第一步 獲取牛肉粉 欲取代的位置 的序...

演算法 拖動排序

選單 菜品排序問題 在菜品分類和菜品表中,新增排序字段,以供使用者排序。新增時需要插入序號 max 1 查詢時按照序號從低到高的順序排序 排序演算法 以菜品為例 牛肉粉 序號1 雞蛋飯 序號2 烤羊肉 序號3 滷豆腐 序號4 現在需要將 滷豆腐 放在第一位 1 第一步 獲取牛肉粉 欲取代的位置 的序...