orderBy新寫法


通常,我們處理排序規則的處理方法是在sql 語句中order by create_time desc,

 

但是這時我們需要從控制器中一步步找到該方法,操作多。

 

我們試着將業務邏輯拆分到控制器 中,

 

把排序規則定義在控制器中該如何寫呢

xml:

 1 <if test="orderByClause != null" > 2 order by ${orderByClause} 3 </if> 

 

model:

 1     protected boolean distinct;
 2     
 3     protected String orderByClause;
 4     
 5     public void setOrderByClause(String orderByClause) {
 6         this.orderByClause = orderByClause;
 7     }
 8 
 9     public String getOrderByClause() {
10         return orderByClause;
11     }
12 
13     public void setDistinct(boolean distinct) {
14         this.distinct = distinct;
15     }
16 
17     public boolean isDistinct() {
18         return distinct;
19     }

 

控制器中代碼,比如設置醫院排序規則:

1 GhHospitalExample example = new GhHospitalExample();
2         example.setOrderByClause(" b.area_num, a.SHOW_NO, nvl(a.BOOK_COUNT,0) desc, a.alias_name");
3         return ghHospitalDao.selectByExample(example);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM