【瑞吉外卖】学习笔记-day2:(二)员工信息分页查询

发布于:2022-10-12 ⋅ 阅读:(351) ⋅ 点赞:(0)

需求分析:

以分页的方式来展示列表数据。

实现流程:

  • 页面发送ajax请求,将分页查询参数(page、pageSize、name)提交到服务端
  • 服务端Controller接收页面提交的数据并调用Service查询数据
  • Service调用Mapper操作数据库,查询分页数据
  • Controller将查询到的分页数据响应给页面
  • 页面接收到分页数据并通过ElementUI的Table组件展示到页面上

需配置MybatisPlus分页插件

 

 了解学习MybatisPlus分页:Mybatis-Plus如何使用分页_为了我的架构师的博客-CSDN博客_mybatisplus分页

package com.itheima.reggie.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;

/**
 * 配置MybatisPlus分页插件
 */

@Configuration
public class MybatisPlusConfig {

    //拦截器,分页
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
        return mybatisPlusInterceptor;
    }
}

请求路径:http://localhost:8080/employee/page?page=1&pageSize=10

请求方法:GET

代码开发:

/**
 * 员工信息分页查询
 * @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();
    //添加过滤条件
    queryWrapper.like(StringUtils.isNotEmpty(name),Employee::getName,name); //当name不等于空时
    //添加一个排序条件
    queryWrapper.orderByDesc(Employee::getUpdateTime);

    //执行查询
    employeeService.page(pageInfo,queryWrapper);

    return R.success(pageInfo);
}

一个小问题:为什么后端传给页面的status数据为Integer类型,而到了页面展示效果的时候显示的是已禁用或者正常? 

 因为在前端代码中,当status为1时表示正常,为0时表示已禁用

 

 


网站公告

今日签到

点亮在社区的每一天
去签到