欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

mysql 较为高效的分页_MySQL

程序员文章站 2022-04-13 08:01:33
...
直接上代码

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());

/