Home>Article>Web Front-end> How to implement paging in layui

How to implement paging in layui

angryTom
angryTom Original
2019-07-29 11:06:13 7126browse

How to implement paging in layui

If you want to know more about layui, you can click:layui tutorial

##This is based on the SSM case framework built by myself.

The rendering is as follows

How to implement paging in layui##The pagination jsp and js content modules are temporarily written together. , of course, you can also write a js file

<%@ 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      

Backend implementation

The main place is page , limit , count , and other things can be done by the layui paging plug-in (the jsp page has this code), as long as The three values of page, limit and count can be realized by paging

//分页插件 ,page: { //支持传入 laypage 组件的所有参数(某些参数除外,如:jump/elem) - 详见文档 layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局 ,groups: 1 //只显示 1 个连续页码 ,first: false //不显示首页 ,last: false //不显示尾页 }

Return object type, js will treat this type as json data

@SuppressWarnings("null") @RequestMapping(value = "userlist") @ResponseBody public Object userlist(HttpServletRequest request, HttpServletResponse response) { //分页 String pageNo=request.getParameter("page"); String pagesize=request.getParameter("limit"); String uname=request.getParameter("selectValue"); HashMap map=new HashMap(); map.put("pageNo", (Integer.valueOf(pageNo)-1)); map.put("pagesize", pagesize); //查询总数量 List listsize = user.findAll(); //分页传参page<当前页>和limit<显示数据条数> List list=null; try { list = user.selectAlllist((Integer.parseInt(pageNo)-1)*Integer.parseInt(pagesize),Integer.parseInt(pagesize)); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("条数:"+list.size()); Map result = new HashMap(); int count = listsize.size(); JSONArray json = JSONArray.fromObject(list); String js=json.toString(); //*****转为layui需要的json格式,必须要这一步,博主也是没写这一步,在页面上数据就是数据接口异常 String jso = "{\"code\":0,\"msg\":\"\",\"count\":"+count+",\"data\":"+js+"}"; System.out.println(jso); return jso; }

Corresponding sql

select uid,uname,upass,sex,age,constellation,unative,national,labeltext from user where 1=1 limit #{pageNo},#{pagesize}
and

dao method parameter passing

public List selectAlllist( @Param("pageNo") Integer pageNo ,@Param("pagesize") Integer pagesize);

daoimpl implementation

@Override public List selectAlllist(Integer pageNo, Integer pagesize) { // TODO Auto-generated method stub return user.selectAlllist(pageNo,pagesize); }

Service implementation

public List selectAlllist(Integer pageNo, Integer pagesize);

serviceimpl implementation

@Override public List selectAlllist(Integer pageNo, Integer pagesize) { // TODO Auto-generated method stub return usi.selectAlllist(pageNo,pagesize); }

The above is the detailed content of How to implement paging in layui. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn