当前位置:网站首页>黑马瑞吉外卖之员工信息分页查询
黑马瑞吉外卖之员工信息分页查询
2022-07-24 11:10:00 【兰舟千帆】
前端页面分析
按照后端的逻辑的话,我们其实是可以直接先去运行这个项目,因为我们之前完成了的登录退出功能。只要登录进来器是你就可以看到一个这样的界面。
其实刚进来这个页面你是看不到数据的,因为这样进来台管理页面它其实会做一个自动的分页查询,但是这个后端的功能我们还没有做。
我们在网页检查这个登录的动作就可以。

我们点开这个链接
可以看到它的请求链接,和携带参数。通过这个链接我们就知道如何去写Controller和接收处理数据。不过还是去看看前端的界面,明白一个大概的流程会更加方便我们去操作。
我们的后台管理界面是在index.html这里。所以我们去这个界面来找到这个请求。

index的这个界面,我们找到这个界面。
然后这个页面在member的list的list.html这里。
跟进到这里

这些都是关联的前端跟进。
ElementUI组件展示,就是前端的这些。
vue的data
展示在这里
分页查询功能开发
实体类
package com.jgdabc.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import java.io.File;
import java.io.Serializable;
import java.time.LocalDateTime;
@Data
public class Employee implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private String username;
private String name;
private String password;
private String phone;
private String sex;
private String idNumber;
private Integer status;
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
@TableField(fill = FieldFill.INSERT)
private Long createUser;
@TableField(fill = FieldFill.INSERT_UPDATE)
private Long updateUser;
}
@TableField 功能是让这些字段自动填充,具体在什么时候自动化填充,可以指定。
具体的填充信息
但是单单填这样的一个注解还不行,我们需要去做一个数据处理类
package com.jgdabc.common;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.mysql.cj.log.Log;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
//自定义的源数据处理器
@Component
@Slf4j
public class MyMetaObjextHander implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
log.info("公共字段自动填充[insert]....");
log.info(metaObject.toString());
metaObject.setValue("createTime", LocalDateTime.now());
metaObject.setValue("updateTime", LocalDateTime.now());
metaObject.setValue("createUser",BaseContext.getCurrentId());
metaObject.setValue("updateUser",BaseContext.getCurrentId());
}
@Override
public void updateFill(MetaObject metaObject) {
log.info("公共字段自动填充[insert]");
log.info(metaObject.toString());
metaObject.setValue("updateTime", LocalDateTime.now());
metaObject.setValue("updateUser",BaseContext.getCurrentId());
// long id = Thread.currentThread().getId();
// log.info("当前线程的id为{}",id);
}
}
BaseContext放在后面说。
实体类定义完后,我们来看dao层,也就是mapper类。
package com.jgdabc.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jgdabc.entity.Employee;
import org.apache.ibatis.annotations.Mapper;
// Mapper 继承该接口后,无需编写 mapper.xml 文件,即可获得CRUD功能
@Mapper
public interface EmployMapper extends BaseMapper<Employee> {
}
service层
package com.jgdabc.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.jgdabc.entity.Employee;
import org.springframework.stereotype.Service;
/** * 除了 BaseMapper 接口,MyBatis Plus 还提供了 IService 接口,该接口对应 Service 层。MyBatis Plus 的通用 Service CRUD 实现了 IService 接口, * 进一步封装 CRUD。为了避免与 BaseMapper 中定义的方法混淆,该接口使用 get(查询单行)、remove(删除)、list(查询集合)和 page(分页)前缀命名的方式进行区别。 */
public interface EmployService extends IService<Employee> {
}
service的实现层
package com.jgdabc.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jgdabc.entity.Employee;
import com.jgdabc.mapper.EmployMapper;
import com.jgdabc.service.EmployService;
import org.springframework.stereotype.Service;
/* MyBatis Plus 使用 ServiceImpl 类实现 IService 接口 */
@Service
public class EmployServiceImpl extends ServiceImpl<EmployMapper, Employee> implements EmployService {
}
这几个都是固定的逻辑。
现在我们来看Controller的实现方法
员工信息查询
@RequestMapping("/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);//前端传过来分页的当前码和分页的每一页的大小
log.info("pageinfo:{}",pageInfo);
// 构造分页构造器
// 条件构造器
LambdaQueryWrapper<Employee> lambdaQueryWrapper = new LambdaQueryWrapper();
// 添加过滤条件
lambdaQueryWrapper.like(StringUtils.isNotEmpty(name),Employee::getName,name);
// 添加排序条件
lambdaQueryWrapper.orderByDesc(Employee::getUpdateTime);
employService.page(pageInfo,lambdaQueryWrapper);
return R_.success(pageInfo);
需要一个分页拦截器的类
package com.jgdabc.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;
@Configuration
//Mybatis拦截器设计的一个初衷就是为了供用户在某些时候可以实现自己的逻辑而不必去动Mybatis固有的逻辑。
//配置mp的分页插件
public class MybatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor()
{
MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
return mybatisPlusInterceptor;
}
}
可以注意到这个方法的泛型是Page,也就是我们最后返回的也是Page类型的pageInfo。为什么要这样返回,我们可以先看一下前端需要的数据。
records,total,我们的实体类并没有这样的字典属性。但是我们的pageInfo有。我们可以点进去看。我们点进去Page这个类。
你看这些字段就是我们需要的,所以我们要用Page这个泛型。最终的数据全部会自动封装在pageInfo里面,所以我们无需其他的处理。
边栏推荐
- Collation of important MySQL configuration parameters
- UNIX C language POSIX mutex thread synchronization
- 浅析拉格朗日乘数法及其对偶问题
- Publish local images to Alibaba cloud
- MySQL查询字段匹配某个规则的记录
- Download path of twincat3 versions
- E2PROM read / write (xiicps) on PS side of zcu102 board
- read_ CSV error: 'GBK' codec can't decode byte 0xb4 in position 274: illegal multibyte sequence
- No one knows what ingredients tiktok's latest popular product pink sauce contains
- 聊聊软件测试-自动化测试框架
猜你喜欢

Simply understand MODBUS function code and partition

聊聊软件测试-自动化测试框架

在idea中System.getProperty(“user.dir“)识别到模块(module)路径的方法:Working directory的设置

RS485 communication OSI model network layer

变频器的工作原理和功能应用

Stm32+esp8266+mqtt protocol connects Alibaba cloud Internet of things platform

【直播报名】Location Cache 模块浅析及 OCP 监控、报警详解

Capture and handling of JDBC exception sqlexception

Redismission watchdog implementation mechanism can be understood at a glance

STM32+ESP8266+MQTT协议连接阿里云物联网平台
随机推荐
Ask n! How many zeros are there behind
Blue Bridge Cup provincial match training camp - Calculation of date
自动推理的逻辑06--谓词演算
The U.S. Department of Homeland Security launched an investigation into the electronic communication records deleted by the secret service during the riots in the Capitol
[interview: Basics 05: quick sort]
Redismission inventory deduction demo
RRPN:Arbitrary-Oriented Scene Text Detection via Rotation Proposals
HDU 3351:Seinfeld
MySQL paging
Four components and working principle of frequency converter
Druid encryption command
《Nature》论文插图复刻第3期—面积图(Part2-100)
pip更新命令
2018 arXiv | Objective-Reinforced Generative Adversarial Networks (ORGAN) for Sequence Generation Mo
【Golang】golang中time类型的before方法
【白帽子讲Web安全】第一章 我的安全世界观
Value and technical thinking of vectorization engine for HTAP
浅析拉格朗日乘数法及其对偶问题
SQL optimization skills and precautions
High speed ADC test experience