天天看點

easyui系列-datagrid分頁 實體分頁

datagrid分頁:用戶端和服務端分頁

這裡用服務端分頁,實時性好。

data-options="
                iconCls: 'icon-edit',
                singleSelect: true,
                toolbar: '#allStuInfoTb',
                url: '/getAllStuInfo',
                method: 'get',
<%--                onEndEdit: onEndEdit,--%>
                rownumbers:true,
                loadFilter:loadFilter,
                pagination: true,
                pageSize:2,
                pageList:[2,20,30,40,50],
                idField:'id',
            ">
           

pagination: true,

注意:

pageSize:2,與 pageList:第一個要對應不然出錯。

這樣就行,他會自動向後端傳兩個參數page 第幾頁,rows每頁行數。

傳回給前端:

public class pageStus {
    private int Total;
    private List<Student> rows;

    @Override
    public String toString() {
        return "pageTest{" +
                "Total=" + Total +
                ", rows=" + rows +
                '}';
    }

//setter getter
}

           

controller層

@ResponseBody
    public pageStus getAllStuInfo(int page, int rows){
        return adminService.getAllStuInfo(page,rows);
    }
           

service:

public pageStus getAllStuInfo(int page, int rows){
        pageStus pageStus = new pageStus();
        int total = sd.getStuTotal();
        int start= (page - 1) * rows;
        int end = start+rows;
        List<Student> list = sd.findAllStu(start,end);
        for (Student student:list) {
            student.setClazz(cd.findClazzByStuID(student.getId()));
            student.setStuInfo(sid.findStuInfoByID(student.getId()));
        }
        pageStus.setTotal(total);
        pageStus.setRows(list);
        return pageStus;
    }
           

mapper.xml

<select id="findAllStu" resultType="com.yu.POJO.Student">
        select * from stu limit #{start},#{end}
    </select>

    <select id="getStuTotal" resultType="Integer">
        select count(*) from stu
    </select>
           

繼續閱讀