springboot+maybatis中layui分页

本文介绍了如何在SpringBoot+Mybatis项目中集成Layui进行分页操作,包括所需的依赖引入、Dao层、Service、ServiceImpl、Controller及Mapper的配置,并详细讲解了前端HTML界面的实现步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

springboot+mybatis中layui的分页
1.各种包需要提前导入注意路径
2.Dao层

public interface UserDao {

    /**
     * 查询用户信息
     * @param map
     * @return
     */
    List<Map> getUserList(Map map);
    /**
     * 用户分页
     * @return
     */
    int getUserCount();
}

3.Service

public interface UserService {
    /**
     * 获取用户
     * @param map
     * @return
     */
    List<Map> getUserList(Map map);
    /**
     * 用户分页
     * @return
     */
    int getUserCount();
}

4.ServiceImpl

@Service
public class UserServiceImpl implements UserService{
    @Autowired
    private UserDao userDao;
    @Override
    public List<Map> getUserList(Map map) {
        int pageNo = map.get("pageNo") == null ? 1 : Integer.valueOf(map.get("pageNo")+"");
        int pageSize = map.get("pageSize") == null ? 10 : Integer.valueOf(map.get("pageSize")+"");
        map.put("start",(pageNo-1)*pageSize);
        map.put("end",pageNo*pageSize+1);
        return userDao.getUserList(map);
    }
    @Override
    public int getUserCount() {
        return userDao.getUserCount();
    }
}

4.Controller

package com.pro.sm.controller.user;

import com.pro.sm.service.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * className:UserController
 * discriptoin:
 * author:张晓峰
 * createTime:2018-11-23 09:28
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("/list")
    @ResponseBody
    public Object getUserList(@RequestParam Map map){
        List<Map> user = userService.getUserList(map);
        int count = userService.getUserCount();
        System.out.println(count);
        Map tempMap = new HashMap();
        tempMap.put("code",0);
        tempMap.put("msg","");
        tempMap.put("count",count);
        tempMap.put("data",user);

        System.out.println(user);
        return tempMap;
    }
    @RequestMapping("/toList")
    public String toList(Map map){

        return "user";
    }
}

5.Mapper

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.pro.sm.dao.user.UserDao">
    <select id="getUserList" resultType="map">
        select * from (select rownum rn,t.* from tb_user t where rownum &lt; #{end}) a where a.rn &gt; #{start}
    </select>
    <select id="getUserCount" resultType="int">
        select count (*) from tb_user
    </select>
</mapper>

6.Html界面

layui.use('table', function(){
         var table = layui.table;

         table.render({
             elem: '#userlist'
             ,title: '用户数据表'
             ,height:790
             ,width:1910
             ,url: '/sb/user/list'
             ,toolbar: '#toolbarDemo'
             ,page: true
             ,even: true
             ,size: 'lg'
             ,cols:[ [
                 {checkbox: true, fixed: true}
                 ,{field: 'USER_ID', title: '序号', width:300, sort: true, unresize: true ,fixed: 'left'}
                 ,{field: 'USER_NAME', title: '姓名', width:310}
                 ,{field: 'USER_GENDER', title: '性别', width:310,templet:'#SEX'}
                 ,{field: 'USER_AGE', title: '年龄', width:310}
                 ,{field: 'USER_EMAIL', title: '邮箱', width:310}
                 ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:310}
             ] ]
             ,request: {
                 pageName: 'pageNo',//页码的参数名称,默认:page
                 limitName: 'pageSize' //每页数据量的参数名,默认:limit
             },
             limits: [5, 10, 15], //显示
             limit: 5 //每页默认显示的数量
         })
     })
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值