码迷,mamicode.com
首页 > 数据库 > 详细

mysql 较为高效的分页

时间:2014-06-26 07:21:26      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:mysql   java基础   

直接上代码

DaoImpl:

/**
* 开发转让页面展示 ,查询搜索数据,并且分页展示
* @param zrdp 搜索条件封装对象
* @return
*/
@SuppressWarnings("unchecked")
public List<Zrdpxx>  showAllZrdpxxPageindex(Zrdpxx zrdp,int pageindex,String keys) {
String sql ="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());
// }
//



/**
* 开发转让页面展示 ,查询满足条件的开发转让店铺信息
* @param zrdp 搜索条件封装对象
* @return
*/
@SuppressWarnings("unchecked")
public int showAllZrdpxx(Zrdpxx zrdp,String keys) {
String sql ="select count(dpxx_id) 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+"%‘)";
}
}

Object oo =  getSession().createSQLQuery(sql).uniqueResult();
return Integer.parseInt(oo.toString());
 
}


Action:

/**
* 开发转让展示 ,追加对象搜索
* @return 集合
*/
public String getZrdpxxByzr(){
if(pid==1){
allcounts = zrDao.showAllZrdpxx(zrdpxx,keys);
}
forkaifazrlist = zrDao.showAllZrdpxxPageindex(zrdpxx, pid, keys);
kfmap.put("allkaifazr",allcounts);
kfmap.put("allkaifazrPageindex", forkaifazrlist);
if(forkaifazrlist!=null){
return "showallsuc";
}
return "fail";
}


js:


function showws(){
zrshopids =$.trim($("#txt_infoid").val());
var isnums = isNaN(zrshopids);
var yanzhengs = /^\s*$/;
var isspaces =yanzhengs.test(zrshopids);
if(isnums){
zrshopids=-1;
}
if(isspaces){
zrshopids = "";
}
if($("#txt_infoid").val().indexOf(".")!=-1){
alert("亲,请输入正确的店铺ID!");
}
else{
$("#showtable tr:not(:first)").remove();
$("#bottompage").html("");
$.post("zrAction!getallDpxx.action",{"pid":pageindex,"zrdpxx.dpxxPyetai":$("#ddl_yetaicate").val().substring(3,7),"zrdpxx.dpxxHtaiztai":$("#ddl_after").val(),"zrdpxx.dpxxZyetai":$("#ddl_yetai").val(),"zrdpxx.dpxxQtaiztai":$("#ddl_before").val(),"zrdpxx.dpxxHtaiztai":$("#ddl_after").val(),"zrdpxx.dpxxSfouzdin":$("#istopno").val(),"tel":$.trim($("#txt_key").val()),"dpidsss":zrshopids,"showwhotel":$("#showwhotel").val()},
function(data){
if(data["zrdxpxxPageindexCount"].length<=0){
alert("没有符合当前条件的数据!");
}
else{
$.each(data["zrdxpxxPageindexCount"],function(i,list){
$tr=$("<tr></tr>");
$td12 =$(" <td align=‘center‘ valign=‘top‘ style=‘border-right:0;‘><input type=‘checkbox‘ name =‘row_checkbox‘ id =‘checkDo‘ value=‘"+list.dpxxId+"‘/></td>");
$td1=$("<td align=‘center‘ valign=‘top‘><a href=‘TransferManager24.1.jsp?dpidsss="+list.dpxxId+"‘ target=‘_blank‘>"+list.dpxxId+"</a></td>");
$td2 =$("<td align=‘center‘ valign=‘top‘>"+list.dpxxFbusjian.substring(0,10)+"</td>");
switch(list.dpxxXxilyuan){
case 1:
$td3 =$("<td align=‘center‘ valign=‘top‘>客户</td>");                                                                                                                                                                                                                                                                                       
break;
case 4:
$td3 =$("<td align=‘center‘ valign=‘top‘>外网</td>");
break;
case 2:
$td3 =$("<td align=‘center‘ valign=‘top‘>报纸</td>");
break;
case 3:
$td3 =$("<td align=‘center‘ valign=‘top‘>扫街</td>");
break;
case 5:
$td3 =$("<td align=‘center‘ valign=‘top‘>其他</td>");
break;
}
$td4 =$("<td align=‘center‘ valign=‘top‘>"+list.dpxxZyetai+"</td>");
$td5 =$("<td align=‘center‘ valign=‘top‘>"+list.dpxxQyu+"</td>");
$td7 =$("<td align=‘center‘ valign=‘top‘>"+list.dpxxBti+"</td>");
$td8 =$("<td align=‘center‘ valign=‘top‘>"+list.dpxxJtidzhi+"</td>");
$td13=$("<td align=‘center‘ valign=‘top‘>"+list.mytel+"</td>");
if(list.dpxxSfouzdin==1){
$td9 =$("<td align=‘center‘ valign=‘top‘>是</td>");
}
if(list.dpxxSfouzdin==2){
$td9 =$("<td align=‘center‘ valign=‘top‘>否</td>");
}
if(list.dpxxQtaiztai==1){
$td10 =$("<td align=‘center‘ valign=‘top‘>显示</td>");
}
if(list.dpxxQtaiztai==2){
$td10 =$("<td align=‘center‘ valign=‘top‘>不显示</td>");
}
switch(list.dpxxHtaiztai){
case 1:
$td11 =$("<td align=‘center‘ valign=‘top‘>屏蔽</td>");
break;
case 2:
$td11 =$("<td align=‘center‘ valign=‘top‘ style=‘color:green‘>开发</td>");
break;
case 3:
$td11 =$("<td align=‘center‘ valign=‘top‘ style=‘color:blue‘>重点</td>");
break;
case 4:
$td11 =$("<td align=‘center‘ valign=‘top‘ style =‘color:red‘>售后</td>");
break;
case 5:
$td11 =$("<td align=‘center‘ valign=‘top‘ style=‘color:#A757A8‘>案例</td>");
break;
}

$tr.append($td1).append($td2).append($td3).append($td4).append($td5).append($td7).append($td8).append($td13).append($td9).append($td10).append($td11).append($td12);
$("#showtable").append($tr);
});
pagesize = data["zrdxpxxAllCount"]%maxresult==0?parseInt(data["zrdxpxxAllCount"]/maxresult):parseInt(data["zrdxpxxAllCount"]/maxresult)+1;
var $uppage = $("<a href=‘javascript:go(true)‘><<上一页&nbsp;&nbsp&nbsp;&nbsp</a>");
var $span =$("<span style=‘font-size:12px‘>共"+data["zrdxpxxAllCount"]+"条&nbsp;&nbsp第"+pageindex+"页&nbsp;&nbsp总"+pagesize+"页</span>");
var $downpage =$("<a href=‘javascript:go(false)‘>&nbsp;&nbsp&nbsp;&nbsp下一页>>&nbsp;&nbsp&nbsp;&nbsp</a>");
var $select = $("<select onchange=‘javascript:gotos()‘ id=‘gotosid‘></select>");
for(var i = 1;i<=pagesize;i++){
$select.append("<option value="+i+">第"+i+"页</option>");
}

$("#bottompage").append($uppage).append($span).append($downpage).append($select);
$("#gotosid").find("option[value=‘"+pageindex+"‘]").attr("selected","selected");
}

});
}
}



bubuko.com,布布扣


mysql 较为高效的分页,布布扣,bubuko.com

mysql 较为高效的分页

标签:mysql   java基础   

原文地址:http://blog.csdn.net/u011598529/article/details/34441627

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!