这是第二章 没有看过的可以点超链接跳转第一篇
分页查询
由页面得知请求方法是Get请求 请求路径是page 参数是 page和pageSize
页面上边有一个查询按钮 得知 还有一个参数name
我们使用Mybatis-Plus给我们的分页查询Page
@GetMapping("page")
public R<Page> page(int page,int pageSize,String name){
//分页构造器
Page pageInfo = new Page(page,pageSize);
//条件构造器
LambdaQueryWrapper<Employee> queryWrapper=new LambdaQueryWrapper<>();
//这里使用模糊查询**like** 使用等值查询eq需要把所有都打出来
queryWrapper.like(!StringUtils.isEmpty(name),Employee::getName,name);
//根据修改时间降序排列
queryWrapper.orderByDesc(Employee::getUpdateTime);
//执行查询
employeeService.page(pageInfo,queryWrapper);
return R.success(pageInfo);
}
还需要一个MP提供的分页插件
@Configuration
public class MybatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
//里边是DbType.MYSQL自己的数据库 我的是Mysql
}
}
修改员工信息 修改status字段
根据id修改状态
@PutMapping //本来只是更新status字段 这个把员工所有都更新了
public R<String> update(@RequestBody Employee employee,HttpSession session){
Long id = (Long) session.getAttribute("employee");
employee.setUpdateTime(LocalDateTime.now());
employee.setUpdateUser(id)