Home Web Front-end Layui Tutorial How to implement paging in layui

How to implement paging in layui

Jul 29, 2019 am 11:06 AM
layui

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+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
 <link rel="stylesheet" href="<%=basePath %>js/layui/css/layui.css">
    <script type="text/javascript" src="<%=basePath %>js/layui/layui.all.js"></script>
    <script type="text/javascript" src="<%=basePath %>js/layui/layui.js"></script>
    <script  type="text/javascript" src="<%=basePath %>js/jquery-3.3.1.min.js"></script>
  <!-- 注意:如果你直接复制所有代码到本地,上述css路径需要改成你本地的 -->
</head>
<body>
 <div class="layui-form-item">
 <div class="layui-input-inline">
     <input type="text" name="selectValue" id="selectValue" lay-verify="required" placeholder="客户姓名,电话" autocomplete="off" class="layui-input">
 </div>
 <button class="layui-btn" type="button"  id="selectButton">搜索</button>
 </div>
 <table class="layui-hide" id="test"></table>
 <script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail" οnclick="yhck()">查看</a>
  <a class="layui-btn layui-btn-xs" lay-event="edit"οnclick="yhbj()">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"οnclick="yhsc()">删除</a>
</script>
 <script>
layui.use(&#39;table&#39;, function(){
  var table = layui.table;
  var ids =new Array();
  var curPath=window.document.location.href;  
  var localhostPaht=curPath.substring(0,32);
  var selectValue=document.getElementById("selectValue").value;
  console.log(selectValue);
  table.render({
    elem: &#39;#test&#39;
   // ,url:localhostPaht+&#39;userlist.do?page=&#39;+page+&#39;&limit=&#39;+limit+&#39;&selectValue=&#39;+selectValue
    ,url:localhostPaht+&#39;userlist.do&#39;
    //分页插件
    ,page: { //支持传入 laypage 组件的所有参数(某些参数除外,如:jump/elem) - 详见文档
    	layout: [&#39;limit&#39;, &#39;count&#39;, &#39;prev&#39;, &#39;page&#39;, &#39;next&#39;, &#39;skip&#39;] //自定义分页布局
        ,groups: 1 //只显示 1 个连续页码
        ,first: false //不显示首页
        ,last: false //不显示尾页
        
      }
    //显示字段参数
    ,cols: [[
      {field:&#39;uid&#39;, width:&#39;5%&#39;, title: &#39;ID&#39;, sort: true}
      ,{field:&#39;uname&#39;, width:&#39;10%&#39;, title: &#39;用户名&#39;}
      ,{field:&#39;sex&#39;, width:&#39;8%&#39;, title: &#39;性别&#39;}
      ,{field:&#39;national&#39;, width:&#39;8%&#39;, title: &#39;民族&#39;, sort: true}
      ,{field:&#39;age&#39;, width:&#39;8%&#39;, title: &#39;年龄&#39;}
      ,{field:&#39;constellation&#39;, title: &#39;星座&#39;, width:&#39;10%&#39;}
      ,{field:&#39;unative&#39;, width:&#39;10%&#39;, title: &#39;籍贯&#39;, sort: true}
      ,{field:&#39;labeltext&#39;, title: &#39;描述&#39;, width:&#39;20%&#39;}
      ,{fixed: &#39;right&#39;, width:&#39;20%&#39;, title: &#39;基本操作&#39;,align:&#39;center&#39;, toolbar: &#39;#barDemo&#39;}
    ]]
   
  });
});
</script>
</body>
</html>
Copy after login

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: [&#39;limit&#39;, &#39;count&#39;, &#39;prev&#39;, &#39;page&#39;, &#39;next&#39;, &#39;skip&#39;] //自定义分页布局
        ,groups: 1 //只显示 1 个连续页码
        ,first: false //不显示首页
        ,last: false //不显示尾页
        
      }
Copy after login

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<String, Object> map=new HashMap<String, Object>();
		map.put("pageNo", (Integer.valueOf(pageNo)-1));
		map.put("pagesize", pagesize);
		//查询总数量
		List<User> listsize = user.findAll();
		//分页传参page<当前页>和limit<显示数据条数>
		List<User> 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<String, Object> result = new HashMap<String, Object>();
		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;
   
	}
Copy after login

Corresponding sql

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

dao method parameter passing

  public 	List<User> selectAlllist(
    		@Param("pageNo") Integer pageNo
    		,@Param("pagesize") Integer pagesize);
Copy after login

daoimpl implementation

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

Service implementation

public List<User> selectAlllist(Integer pageNo, Integer pagesize);
Copy after login

serviceimpl implementation

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

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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to set up jump on layui login page How to set up jump on layui login page Apr 04, 2024 am 03:12 AM

Layui login page jump setting steps: Add jump code: Add judgment in the login form submit button click event, and jump to the specified page through window.location.href after successful login. Modify the form configuration: add a hidden input field to the form element of lay-filter="login", with the name "redirect" and the value being the target page address.

How to get form data in layui How to get form data in layui Apr 04, 2024 am 03:39 AM

layui provides a variety of methods for obtaining form data, including directly obtaining all field data of the form, obtaining the value of a single form element, using the formAPI.getVal() method to obtain the specified field value, serializing the form data and using it as an AJAX request parameter, and listening Form submission event gets data.

How layui implements self-adaptation How layui implements self-adaptation Apr 26, 2024 am 03:00 AM

Adaptive layout can be achieved by using the responsive layout function of the layui framework. The steps include: referencing the layui framework. Define an adaptive layout container and set the layui-container class. Use responsive breakpoints (xs/sm/md/lg) to hide elements under specific breakpoints. Specify element width using the grid system (layui-col-). Create spacing via offset (layui-offset-). Use responsive utilities (layui-invisible/show/block/inline) to control the visibility of elements and how they appear.

What is the difference between layui and vue? What is the difference between layui and vue? Apr 04, 2024 am 03:54 AM

The difference between layui and Vue is mainly reflected in functions and concerns. Layui focuses on rapid development of UI elements and provides prefabricated components to simplify page construction; Vue is a full-stack framework that focuses on data binding, component development and state management, and is more suitable for building complex applications. Layui is easy to learn and suitable for quickly building pages; Vue has a steep learning curve but helps build scalable and easy-to-maintain applications. Depending on the project needs and developer skill level, the appropriate framework can be selected.

What does layui mean? What does layui mean? Apr 04, 2024 am 04:33 AM

layui is a front-end UI framework that provides a wealth of UI components, tools and functions to help developers quickly build modern, responsive and interactive web applications. Its features include: flexible and lightweight, modular design, rich components, Powerful tools and easy customization. It is widely used in the development of various web applications, including management systems, e-commerce platforms, content management systems, social networks and mobile applications.

How to transfer data in layui How to transfer data in layui Apr 26, 2024 am 03:39 AM

The method of using layui to transmit data is as follows: Use Ajax: Create the request object, set the request parameters (URL, method, data), and process the response. Use built-in methods: Simplify data transfer using built-in methods such as $.post, $.get, $.postJSON, or $.getJSON.

What language is layui framework? What language is layui framework? Apr 04, 2024 am 04:39 AM

The layui framework is a JavaScript-based front-end framework that provides a set of easy-to-use UI components and tools to help developers quickly build responsive web applications. Its features include: modular, lightweight, responsive, and has complete documentation and community support. layui is widely used in the development of management backend systems, e-commerce websites, and mobile applications. The advantages are quick start-up, improved efficiency, and easy maintenance. The disadvantages are poor customization and slow technology updates.

The difference between layui framework and vue framework The difference between layui framework and vue framework Apr 26, 2024 am 01:27 AM

layui and vue are front-end frameworks. layui is a lightweight library that provides UI components and tools; vue is a comprehensive framework that provides UI components, state management, data binding, routing and other functions. layui is based on a modular architecture, and vue is based on a componentized architecture. layui has a smaller ecosystem, vue has a large and active ecosystem. The learning curve of layui is low, and the learning curve of vue is steep. Layui is suitable for small projects and rapid development of UI components, while vue is suitable for large projects and scenarios that require rich functions.

See all articles