十:区别Filter排序与hql排序,带筛选条件

发布时间:2016-12-9 15:53:10 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"十:区别Filter排序与hql排序,带筛选条件",主要涉及到十:区别Filter排序与hql排序,带筛选条件方面的内容,对于十:区别Filter排序与hql排序,带筛选条件感兴趣的同学可以参考一下。

区别Filter排序与hql排序,带筛选条件   Action:   public String listCompany() throws Exception {       List<PropertyFilter> filters = PropertyFilter.buildFromHttpRequest(Struts2Utils.getRequest());       page.setPageNo(Integer.parseInt(Struts2Utils.getRequest()            .getParameter("page")));       page.setPageSize(Integer.parseInt(Struts2Utils.getRequest()            .getParameter("pagesize")));       //设置默认排序方式       if (!page.isOrderBySetted()) {         page.setOrderBy("companyid");         page.setOrder(Page.DESC);       } [d1]    page = companyManager.searchCompany(page, filters) ;       String result = reverseLigerGridJsonData(page) ;       Struts2Utils.renderJson(result) ;       returnNONE;    }   Service: 方式一:filter排序 @Transactional(readOnly = true)    public Page<Company> searchCompany(final Page<Company> page, final List<PropertyFilter> filters) {       return companyDao.findPage(page, filters);    } 方式二: //按筛选条件查询商家信息    @Transactional(readOnly = true)    public Page<Company> searchCompany(final Page<Company> page, final List<PropertyFilter> filters) {       //开始-----------------------------------------------       String hql ="select c from Company c where 1=1";       for(PropertyFilter filter : filters){         String fieldname = filter.getPropertyName();         String filedValue = filter.getMatchValue().toString();             if (fieldname.equals("companycode")&&!filedValue.equals(""))             hql += " and c.companycode like '%"+filedValue+"%'";             if (fieldname.equals("companyname")&&!filedValue.equals(""))              hql +=" and c.companyname like '%"+filedValue+"%'";             if (fieldname.equals("status")&&!filedValue.equals("")){             if(filedValue.equals(""))               continue;             if(filedValue.contains(";")){                String statusStr=filedValue.replace(";", ",");                   hql +=" and c.status in ("+statusStr+")";             }else{                hql +=" and c.status in ("+filedValue+")";             }                          }       }       if (!page.isOrderBySetted()) {         hql += " order by companyid desc";       }       else       {         hql += " order by "+page.getOrderBy()+" "+page.getOrder();       } [d2]    //结束-----------------------------------------------       returncompanyDao.findPage(page, hql[d3] );    }   Dao:  [d1]  [d2]Hql把排序加进来  [d3]用hql不用filter排序的时候需要在manager写上面一部分代码

上一篇:WeakReference 3 - 其他Reference
下一篇:java关键字catch

相关文章

相关评论