Home  >  Article  >  Database  >  mysql 较为高效的分页_MySQL

mysql 较为高效的分页_MySQL

WBOY
WBOYOriginal
2016-06-01 13:07:351175browse

直接上代码

DaoImpl:

/**

* 开发转让页面展示 ,查询搜索数据,并且分页展示

* @param zrdp 搜索条件封装对象

* @return

*/

@SuppressWarnings("unchecked")

public List  showAllZrdpxxPageindex(Zrdpxx zrdp,int pageindex,String keys) {

Stringsql ="select * from zrdpxx where dpxx_htaiztai = 2";

if(zrdp!=null){

if(zrdp.getDpxxId()!=null&&!zrdp.getDpxxId().equals("")){

sql+=" and dpxx_id =" +zrdp.getDpxxId();

}

if(zrdp.getDpxxQyu()!=null&&!zrdp.getDpxxQyu().equals("-选择区域-")){

sql+=" and dpxx_qyu = '"+zrdp.getDpxxQyu()+"'";

}

if(zrdp.getDpxxPyetai()!=null&&!zrdp.getDpxxPyetai().equals("")){

sql+=" and dpxx_pyetai = '"+zrdp.getDpxxPyetai()+"'";

}

if(zrdp.getDpxxZyetai()!=null&&!zrdp.getDpxxZyetai().equals("0")&&!zrdp.getDpxxZyetai().equals("null")){

sql+=" and dpxx_zyetai = '"+zrdp.getDpxxZyetai()+"'";

}

if(zrdp.getBigmji()!=0&&zrdp.getSmlmj()!=-1){

sql += " and dpxx_mji between "+zrdp.getSmlmj()+" and " +zrdp.getBigmji();

}

//开始时间和结束时间均有值

if(zrdp.getBeginTime()!=null&&!zrdp.getBeginTime().equals("")&&zrdp.getEndTimes()!=null&&!zrdp.getEndTimes().equals("null")){

sql +=" and dpxx_fbusjian  between '"+zrdp.getBeginTime()+"' and '"+zrdp.getEndTimes()+"'";

}

//只有开始时间

if(zrdp.getBeginTime()!=null&&!zrdp.getBeginTime().equals("")&&zrdp.getEndTimes()==null){

sql +=" and dpxx_fbusjian  between '"+zrdp.getBeginTime()+"' and now()";

}

if(!("标题 地址 电话").equals(keys)){

sql +=" and (dpxx_bti like '%"+keys+"%' or tel like '%"+keys+"%' or dpxx_jtidzhi like '%"+keys+"%')";

}

sql +=" order by dpxx_fbusjian desc";

}

return getSession().createSQLQuery(sql).addEntity(Zrdpxx.class).setFirstResult((pageindex-1)*20).setMaxResults(20).list();

}

//public int getallzrdpcounts() {

//Object oo = getSession().createSQLQuery("select count(dpxx_id) from zrdpxx where dpxx_htaiztai =2").uniqueResult();

//return Integer.parseInt(oo.toString());

/

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn