首页 > 其他分享 >员工信息分页查询

员工信息分页查询

时间:2023-02-24 19:34:35浏览次数:22  
标签:name pageSize 页面 员工 查询 page 分页

需求分析:系统中的员工很多的时候,如果在一个页面全部展示出来会显得比较乱,不便于查看,所以一般的系统中都会以分页的方式来展示列表数据。

程序执行过程:

(1)页面发送ajax请求,将分页查询参数(page、pageSize、name)提交到服务端

(2)服务端Controller接收页面提交的数据并调用Service查询数据

(3)Service调用Mapper操作数据库,查询分页数据

(4)Controller将查询到的分页数据响应给页面

(5)页面接收到分页数据并通过ElementUI的Table组件展示到页面上。

 

通过MP分页插件实现分页功能。

package com.itheima.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置MP的分页插件
 */
@Configuration
public class MybatisPlusConfig {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        //定义mp拦截器
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
        //添加具体的分页拦截器
        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
        return  mybatisPlusInterceptor;
    }
}

在controller中进行分页查询

    /**
     * 员工信息分页查询
     * @param page
     * @param pageSize
     * @param name
     * @return
     */
    @GetMapping("/page")
    public R<Page> page(int page, int pageSize, String name){
//        log.info("page:{}, pageSize:{}, name:{}", page, pageSize, name);

        //构造分页构造器
        Page pageInfo = new Page(page, pageSize);

        //构造条件构造器
        LambdaQueryWrapper<Employee> queryWrapper = new LambdaQueryWrapper<Employee>();
        //添加一个过滤条件
        queryWrapper.like(name!=null, Employee::getName, name);
        //添加一个排序条件
        queryWrapper.orderByDesc(Employee::getUpdateTime);
        //执行查询,查询后page内部会将查询结果进行封装到pageInfo中
        employeeService.page(pageInfo, queryWrapper);
        
        return R.success(pageInfo);
    }

 

标签:name,pageSize,页面,员工,查询,page,分页
From: https://www.cnblogs.com/fxzm/p/17152586.html

相关文章

  • 分享一个基本的分页模板(类似的分页都有工具,注意思想)
    publicclassBasePage<E>implementsSerializable{privatestaticfinallongserialVersionUID=1L;privateIntegerpageNo;privateIntegerpageSi......
  • MongoDB .NET Driver Group By Time Range 按时间分组查询
     先看下一个错误的写法:varfilter=Builders<Model>.Filter.Where(r=>r.Timestamp>startDate&&r.Timestamp<endDate);varresult=Collection.Aggregate()......
  • 不相关子查询
    ​ 【1】什么是子查询?一条SQL语句含有多个select, --引入子查询:--查询所有比“CLARK”工资高的员工的信息--步骤1:“CLARK”工资selectsalfromempwheree......
  • 不相关子查询
    ​ 【1】什么是子查询?一条SQL语句含有多个select, --引入子查询:--查询所有比“CLARK”工资高的员工的信息--步骤1:“CLARK”工资selectsalfromempwheree......
  • 新增员工
    后台系统中可以管理员工信息,通过新增员工来添加后台系统用户,点击【添加员工】按钮跳转到新增页面。将录入的员工数据插入到employee表,需注意,employee表中的username字段加......
  • 99语法:外连接查询
    ​  --innerjoin-on子句:显示的是所有匹配的信息select*fromempeinnerjoindeptdone.deptno=d.deptno;select*fromemp;select*fromdept;--......
  • 99语法:外连接查询
    ​  --innerjoin-on子句:显示的是所有匹配的信息select*fromempeinnerjoindeptdone.deptno=d.deptno;select*fromemp;select*fromdept;--......
  • 99语法:交叉连接,自然连接,内连接查询
    ​ 【1】多表查询引入:实际开发中往往需要针对两张甚至更多张数据表进行操作,而这多张表之间需要使用主键和外键关联在一起,然后使用连接查询来查询多张表中满足要求的数据......
  • 99语法:交叉连接,自然连接,内连接查询
    ​ 【1】多表查询引入:实际开发中往往需要针对两张甚至更多张数据表进行操作,而这多张表之间需要使用主键和外键关联在一起,然后使用连接查询来查询多张表中满足要求的数据......
  • sql查询多个结果逗号分隔为同一行显示
    sql查询数据结果selecte.ctrl_descfromt_ctrl_entryeinnerjoinCodeGroupKeyCodescone.ctrl_code=c.KeyCodewherec.GroupId='3060'ande.roomid=c.RoomIdG......