/** 根据CriterionList组合嵌套条件 */ public Criterion getOrCriterion(CriterionList list) { Criterion c1 = null; Criterion c2 = null; Criterion c3 = null; c1 = list.getParas(0); for (int i = 1; i < list.size(); i++) { c2 = list.getParas(i); c3 = getor(c1, c2); c1 = c3; } return c3; }
/** * 设置ge(>=)查询条件 * * @param keyname * @param keyvalue1 * @param keyvalue2 */ public void ge(String keyname, Object keyvalue) { if (keyvalue != null && keyvalue != "") { criterionList.addPara(Restrictions.ge(keyname, keyvalue)); if (flag) { this.put(keyname, keyvalue); } flag = true; } }
/** * 设置like(模糊)查询条件 * * @param keyname * @param keyvalue1 * @param keyvalue2 */ public void like(String keyname, Object keyvalue) { if (keyvalue != null && keyvalue != "") { // criterionList.addPara(Restrictions.like(keyname, "%" + keyvalue+ "%")); criterionList.addPara(Restrictions.like(keyname, keyvalue)); if (flag) { this.put(keyname, keyvalue); } flag = true; } }
/** * 设置between(之间)查询条件 * * @param keyname * @param keyvalue1 * @param keyvalue2 */ public void between(String keyname, Object keyvalue1, Object keyvalue2) { Criterion c = null; // 写入between查询条件 if (!keyvalue1.equals(null) && !keyvalue2.equals(null)) { c = Restrictions.between(keyname, keyvalue1, keyvalue2); } else if (!keyvalue1.equals(null)) { c = Restrictions.ge(keyname, keyvalue1); } else if (!keyvalue2.equals(null)) { c = Restrictions.le(keyname, keyvalue2); } criterionList.add(c); }
/** * 加载dataTables 默认查询条件 * * @param dataTables */ public void addJqCriteria(DataTables dataTables) { String search = dataTables.getSearch(); // 查询关键字 SortInfo[] sortInfo = dataTables.getSortColumns(); // 排序字段 String[] sColumns = dataTables.getsColumns().split(","); // 字段 if (StringUtil.isNotEmpty(search)) { for (String string : sColumns) { if (string.indexOf("_") == -1) { jqcriterionList.addPara(Restrictions.like(string, "%" + search + "%")); } } add(getOrCriterion(jqcriterionList)); } if (sortInfo.length > 0) { for (SortInfo sortInfo2 : sortInfo) { addOrder("" + sColumns[sortInfo2.getColumnId()] + "", sortInfo2.getSortOrder()); } } }
/** * 设置isNull查询条件 * * @param keyname * @param keyvalue1 * @param keyvalue2 */ public void isNotNull(String keyname) { criterionList.addPara(Restrictions.isNotNull(keyname)); }
/** * 设置in(包含)查询条件 * * @param keyname * @param keyvalue1 * @param keyvalue2 */ public void in(String keyname, Object[] keyvalue) { if (keyvalue != null && keyvalue[0] != "") { criterionList.addPara(Restrictions.in(keyname, keyvalue)); } }