EasyUi,hibernate后台分页

1,准备工具类pageBean

2,通用的方法,将数据以json格式返回

@ResponseBody //将数据以json格式返回
public String searchworkgrid(HttpServletRequest request,HttpServletResponse response,PageBean pageBean)throws IOException{
   //获取当前页
    String page = request.getParameter("page");
    //获取每页显示数
    String rows = request.getParameter("rows");
    pageBean.setCurrentPage(Integer.parseInt(page));
    pageBean.setPageSize(Integer.parseInt(rows));
    supervisionService.pageQuery(pageBean,request);
    this.writePageBean(pageBean,response);
    return null;
}

3,writePageBean方法

/**
 * 分页方法
 * @param pageBean
 * @param response
 */
public void writePageBean(PageBean pageBean, HttpServletResponse response) throws IOException {
    JsonConfig jsonConfig = new JsonConfig();
    jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
    JSONObject jsonObject = JSONObject.fromObject(pageBean, jsonConfig);
    String  json = jsonObject.toString();
    response.setContentType(
            "text/json;charset=UTF-8");
    response.getWriter().print(json);
}

4,pageQuery方法

public void pageQuery(PageBean pageBean, HttpServletRequest request) {
    int currentPage = pageBean.getCurrentPage();
    int pageSize = pageBean.getPageSize();
    //设置编码
    try {
        request.setCharacterEncoding("utf-8");
        //得到离线查询对象
        DetachedCriteria cri = DetachedCriteria.forClass(TRecieveEntity.class);
       //修改查询方式 select count(*) from table
        cri.setProjection(Projections.rowCount());
        //查询总行数
        Session session = systemService.getSession();
        Query query = session.createQuery("select count(*) from  TRecieveEntity tRecieve");
        Long total= (Long) query.list().get(0);
        pageBean.setTotal(total.intValue());//设置总数据量
        //修改查询状态 
        cri.setProjection(null);
        int firstResult = (currentPage - 1) * pageSize;
        int maxResults = pageSize;
        List<TRecieveEntity> rows= this.pageList(cri, firstResult, maxResults);
        pageBean.setRows(rows);
        //当前页展示的数据集合

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

}

5,js页面

<body class="easyui-layout">
<div data-options="region:'center'">
    <table class="easyui-datagrid" title="工单列表" style="width:1338px;height:550px"
           data-options="striped:true,rownumbers:true,singleSelect:false,
           pagination:true,autoRowHeight:false, pageList: [15,30,50],toolbar:'#tb',
           url:'supervisionController.do?searchworkgrid',method:'post'" id="dg">
        <thead>
        <tr>
            <th data-options="field:'ck',checkbox:true"></th>
            <th data-options="field:'id'" width="150" hidden="hidden">主键</th>
            <th data-options="field:'recieveNum',width:150,formatter:titleformater">96005工单编号</th>
            <th data-options="field:'hotlineNum'" width="150">12345工单编号</th>
            <th data-options="field:'proStatus'" width="150">工单状态</th>
            <th data-options="field:'recieveFrom'"  width="150">工单来源</th>
            <th data-options="field:'msgTitle'" width="160">工单标题</th>
            <th data-options="field:'description'" width="160">工单描述</th>
            <th data-options="field:'isSUPERVISE'" width="160">督办状态</th>
            <th data-options="field:'signMan'" width="160">签收员</th>
            <th data-options="field:'problemClass'" width="160" hidden="false">问题分类</th>
            <th data-options="field:'problemName'" width="160">问题分类</th>
            <th data-options="field:'label'" width="160">标签库</th>
        </tr>
        </thead>
    </table>
</div>

6,效果展示

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值