(此代碼拷貝可用)
前端與后端分頁往往存在著數(shù)據(jù) 參數(shù)不對等的問題? ?
例如? 當(dāng)前頁 、每頁的容量等等? ? 使用插件做分頁最開始需要做的是 使得這兩個(gè)數(shù)據(jù)前后端一致
1、服務(wù)端代碼
@RequestMapping("/ssRole")
public ModelAndViewselectRoelByContent(Pagepagepage,UserGroup role) {
????ModelAndView mv = getModelAndView("authority_role/authority_role");
? ? page =rolePageMethodService.getRoleByContent(page,role);
? ? mv.addObject("lists",page);
? ? mv.addObject("roleContent",role);
? ? return mv;
}
注釋?
? ?page內(nèi)部包含的參數(shù):size : 每頁顯示 數(shù)據(jù)條數(shù)? ? ? ?current : 當(dāng)前頁數(shù)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?records : 查詢出的數(shù)據(jù)(list)? ? ? total: 數(shù)據(jù)總數(shù)
?role 對象 通常是進(jìn)行搜索時(shí)的條件??
mapper.xml? 進(jìn)行全查? 不用limit 函數(shù)? ? mybatis-plus? 已經(jīng)封裝好?
????????????????????或者考慮搜索功能 可以進(jìn)行加一些? if? ?語句??
? ? ? ? ? ? ? ? ? ? 例如 :
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? and? name? LIKE? CONCAT(CONCAT('%',#{name}),'%')
前端分頁
var total = ${lists.total!};
layui.use(['laypage', 'layer'], function() {
var laypage =layui.laypage
? ? ? ? , layer =layui.layer;
? ? var form =layui.form;
? ? var total = ${lists.total!};
? ? //核心方法
? ? laypage.render({
????????elem:'demo'
? ? ? ? , count: total//data.length; 數(shù)據(jù)總數(shù)
? ? ? ? , curr: ${lists.current!}? ?//當(dāng)前頁
????????, limit: ${lists.size!}? ? ? ?//每頁數(shù)據(jù)條數(shù)
????????, limits: [5, 8, 10]? ? ? ? //可選的每頁數(shù)據(jù)條數(shù)
????????, layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']? ?
????????, jump:function (obj,first) {
????????????????????if(!first){
????????????????????????????curr = obj.curr;
? ? ? ? ? ? ? ? ????????????var name =$("#roleNameSel").val();
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?window.location.href="${ctx}/rolePage/ssRole?current="+obj.curr
? ? ? ? ? ? ? ? ? ? ????????????????????????????????????????????????+"&size="+obj.limit+"&name="+name;
? ? ? ? ? ? ? ? ? ?}
????????????}
????});
});