mybatisPlus分页c查询
PageHelPer分页
分页条件

分页查询

响应前端

依赖包
<dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.2.0</version> </dependency>
IPage分页
`package com.xxl.controller;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xxl.common.Constast;
import com.xxl.common.DataGridView;
import com.xxl.common.PinyinUtils;
import com.xxl.common.ResultObj;
import com.xxl.domain.Dept;
import com.xxl.domain.Role;
import com.xxl.domain.User;
import com.xxl.service.DeptService;
import com.xxl.service.RoleService;
import com.xxl.service.UserService;
import com.xxl.vo.UserVo;
import cn.hutool.core.util.IdUtil;
@RestController
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;
@Autowired
private DeptService deptService;
@Autowired
private RoleService roleService;
/**
* 用户全查询
*/
@RequestMapping("loadAllUser")
public DataGridView loadAllUser(UserVo userVo) {
IPage<User> page=new Page<>(userVo.getPage(), userVo.getLimit());
QueryWrapper<User> queryWrapper=new QueryWrapper<>();
//判断用户名不为空
queryWrapper.eq(StringUtils.isNotBlank(userVo.getName()), "loginname", userVo.getName()).or().eq(StringUtils.isNotBlank(userVo.getName()), "name", userVo.getName());
queryWrapper.eq(StringUtils.isNotBlank(userVo.getAddress()), "address", userVo.getAddress());
queryWrapper.eq("type", Constast.USER_TYPE_NORMAL);//查询系统用户
queryWrapper.eq(userVo.getDeptid()!=null, "deptid",userVo.getDeptid());
this.userService.page(page, queryWrapper);
System.out.println(userService.getClass().getSimpleName());
List<User> list = page.getRecords();
for (User user : list) {
Integer deptid = user.getDeptid();
if(deptid!=null) {
Dept one =deptService.getById(deptid);
user.setDeptname(one.getTitle());
}
Integer mgr = user.getMgr();
if(mgr!=null) {
User one = this.userService.getById(mgr);
user.setLeadername(one.getName());
}
}
return new DataGridView(page.getTotal(), list);
}`

浙公网安备 33010602011771号