easyui java 分页_easyui和java实现分页

使用框架:springMVC+mybatis,easyui

废话不说,直接上代码,如下:

html代码

监测点等级:

οnclick="select()">查询

 

class="btnsearch" icon="icon-search" οnclick="clear()">重置

js代码

$(function(){

initDatagrid(djdm);

});

function initDatagrid(djdm){

$("#grid").datagrid({

url:"/ycjc/list",

queryParams:{

djdm:djdm

},

method : 'post',

iconCls : 'icon-save',

fitColumns : true,

fit:true,

singleSelect : true,

border : false,

autoRowHeight : true,

striped : true,

nowrap : false,

rownumbers : true,

pagination:true,//分页控件

toolbar : toolbar,

onLoadError : function() {

alert('数据加载失败!');

},

loadMsg : '数据装载中......',

resizeHandle : 'both',

columns:[[

{field:'fid',title:'检测点编号',width:50,hidden:true},

{field:'yjzs',title:'预警总数',width:50,align:"center"},

{field:'jcddj',title:'监测点等级',width:50,align:"center"},

{field:'jcd',title:'监测点',width:100,align:"center"},

{field:'jcgz',title:'监测规则',width:150,align:"center"},

{field:'jcdw',title:'监测单位',width:50,align:"center"},

{field:'jczt',title:'监测状态',width:50,align:"center"}

]]

});

//设置分页控件

var p = $('#grid').datagrid('getPager');

$(p).pagination({

pageSize: 10,//每页显示的记录条数,默认为10

pageList: [5,10,15],//可以设置每页记录条数的列表

beforePageText: '第',//页数文本框前显示的汉字

afterPageText: '页    共 {pages} 页',

displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',

onBeforeRefresh: function () {

},

onSelectPage: function (page, pageSize) {//分页触发

find(page, pageSize);

}

});

}

function find(page, pageSize)

{

$("#grid").datagrid('getPager').pagination({pageSize : pageSize, page : page});//重置

$("#grid").datagrid("loading"); //加屏蔽

$.ajax({

type : "POST",

dataType : "json",

url : "/ycjc/list",

data : {

'page' : page,

'pageSize' : pageSize

},

success : function(data) {

$("#grid").datagrid('loadData',pageData(data.rows,data.total));//这里的pageData是一个对象,用来封装获取的总条数,和数据,data.rows是控制器里面添加的一个map集合的键的名称

$("#grid").datagrid("loaded"); //移除屏蔽

},

error : function(err) {

$.messager.alert('操作提示', '获取信息失败...请联系管理员!', 'error');

$("#grid").datagrid("loaded"); //移除屏蔽

}

});

}

function pageData(list,total){

var obj=new Object();

obj.total=total;

obj.rows=list;

return obj;

}

//查询

function select(){

djdm=$("#djdm").combobox('getValue');

$('#grid').datagrid({

queryParams:{

djdm:djdm

}

});

}

java代码

控制器controller:

@ResponseBody

@RequestMapping("/ycjc/list")

public Map getListView(YjxxTjBean yjxx,

HttpServletRequest request, Integer page, Integer pageSize)

throws Exception

{

JyjbxxBean jyjbxx = (JyjbxxBean) getObject("CURRENT_POLICE");

Map map = new HashMap();

List list;

try

{

list = ycjcService.findYjxxList(yjxx, page, pageSize, jyjbxx);

int total = ycjcService.findYjxxTotal(yjxx, jyjbxx);

//返回的数据list放入rows

map.put("rows", list);

//total总数

map.put("total", list == null ? 0 : total);

}

catch (Exception e)

{

e.printStackTrace();

throw new Exception(e);

}

return map;

}

业务service:

@Override

public List findYjxxList(YjxxTjBean yjxx, Integer page,

Integer pageSize, JyjbxxBean jyjbxx)

{

Map conditions = new HashMap();

// 当前页

page = page == null || page <= 0 ? 1 : page;

// 每页显示条数

pageSize = pageSize == null || pageSize <= 0 ? 10 : pageSize;

int start = (page - 1) * pageSize + 1;

int end = start + pageSize - 1;

if (yjxx != null)

{

conditions.put("djdm", yjxx.getDjdm());

}

if (jyjbxx != null)

{

conditions.put("dwdm", jyjbxx.getGajgjgdm());

}

conditions.put("start", start);

conditions.put("end", end);

return ycjcsjBeanMapper.selectYjxxList(conditions);

}

@Override

public int findYjxxTotal(YjxxTjBean yjxx, JyjbxxBean jyjbxx)

{

Map conditions = new HashMap();

if (yjxx != null)

{

conditions.put("djdm", yjxx.getDjdm());

}

if (jyjbxx != null)

{

conditions.put("dwdm", jyjbxx.getGajgjgdm());

}

return ycjcsjBeanMapper.findYjxxTotal(conditions);

}

mapper.xml代码

SELECT * FROM( SELECT ROW_.*, ROWNUM ROWNUM_ FROM (

) ROW_

WHERE ROWNUM <= #{end}

)

WHERE ROWNUM_ >= #{start}

SELECT T1.FID,

COUNT(t2.jcdid) yjzs,

(SELECT t.fname

FROM COM_DICTIONARY T

WHERE T.FCODE = '145'

AND t.fvalue = t1.djdm) jcddj,

t1.djdm,

t1.jcd,

t1.jcgz,

'省厅' JCDW,

(CASE

WHEN T1.ISQY = '1' THEN

'正常'

ELSE

'停用'

END) JCZT

FROM t_zfba_yjxxsj t0, t_zfba_jcd t1, t_zfba_ycjcsj t2

WHERE t2.fid(+) = t0.fid

and t2.jcdid = t1.fid

and t1.isqy = '1'

and t1.fpdwlx >= get_yjxxdwdmlevel(#{dwdm,jdbcType=VARCHAR})

and BADWDM like case get_yjxxdwdmlevel(#{dwdm,jdbcType=VARCHAR}) WHEN 3 THEN substr(#{dwdm,jdbcType=VARCHAR},1,6)||'%' WHEN 2 THEN substr(#{dwdm,jdbcType=VARCHAR},1,4)||'%' WHEN 1 THEN substr(#{dwdm,jdbcType=VARCHAR},1,2)||'%' end

and t1.djdm=#{djdm,jdbcType=VARCHAR}

GROUP BY T1.FID, T1.DJDM, T1.JCD, T1.JCGZ, T1.ISQY

此为工作笔记,如有疑问或不对的地方,欢迎指出,共同学习共同进步。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值