layui中怎么實(shí)現(xiàn)分頁,很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。
效果圖如下
分頁jsp和js內(nèi)容模塊,暫時(shí)寫在了一塊,當(dāng)然也可以提出來寫個(gè)js文件
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>layui js/layui/css/layui.css">
后臺(tái)實(shí)現(xiàn)
主要的地方就是page<當(dāng)前頁,比如1頁>、limit<當(dāng)前顯示數(shù)據(jù),比如10條數(shù)據(jù)>、count<當(dāng)前表總數(shù)據(jù)條數(shù)>,其他的事情有l(wèi)ayui分頁插件來做(jsp頁面有該代碼),只要page、limit、count這三個(gè)值,分頁就能實(shí)現(xiàn)
//分頁插件 ,page: { //支持傳入 laypage 組件的所有參數(shù)(某些參數(shù)除外,如:jump/elem) - 詳見文檔 layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定義分頁布局 ,groups: 1 //只顯示 1 個(gè)連續(xù)頁碼 ,first: false //不顯示首頁 ,last: false //不顯示尾頁 }
返回object類型,js會(huì)將這個(gè)類型當(dāng)做json數(shù)據(jù)
@SuppressWarnings("null")@RequestMapping(value = "userlist")@ResponseBodypublic Object userlist(HttpServletRequest request, HttpServletResponse response) {//分頁String pageNo=request.getParameter("page");String pagesize=request.getParameter("limit");String uname=request.getParameter("selectValue");HashMapmap=new HashMap ();map.put("pageNo", (Integer.valueOf(pageNo)-1));map.put("pagesize", pagesize);//查詢總數(shù)量List listsize = user.findAll();//分頁傳參page<當(dāng)前頁>和limit<顯示數(shù)據(jù)條數(shù)>List list=null;try {list = user.selectAlllist((Integer.parseInt(pageNo)-1)*Integer.parseInt(pagesize),Integer.parseInt(pagesize));} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}System.out.println("條數(shù):"+list.size());Map result = new HashMap ();int count = listsize.size(); JSONArray json = JSONArray.fromObject(list); String js=json.toString(); //*****轉(zhuǎn)為layui需要的json格式,必須要這一步,博主也是沒寫這一步,在頁面上數(shù)據(jù)就是數(shù)據(jù)接口異常 String jso = "{\"code\":0,\"msg\":\"\",\"count\":"+count+",\"data\":"+js+"}"; System.out.println(jso); return jso; }
對(duì)應(yīng)的sql
select uid,uname,upass,sex,age,constellation,unative,national,labeltext from user where 1=1 limit #{pageNo},#{pagesize}
以及dao方法的傳參
public ListselectAlllist( @Param("pageNo") Integer pageNo ,@Param("pagesize") Integer pagesize);
daoimpl的實(shí)現(xiàn)
@Overridepublic ListselectAlllist(Integer pageNo, Integer pagesize) {// TODO Auto-generated method stubreturn user.selectAlllist(pageNo,pagesize);}
service的實(shí)現(xiàn)
public ListselectAlllist(Integer pageNo, Integer pagesize);
serviceimpl的實(shí)現(xiàn)
@Overridepublic ListselectAlllist(Integer pageNo, Integer pagesize) {// TODO Auto-generated method stubreturn usi.selectAlllist(pageNo,pagesize);}
看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對(duì)創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,的支持。