mybatis-plus多表联合分页查询
1.entity层要写个Vo实体类
2.controller
@AutoLog(value = "员工CURD-分页列表查询")
@ApiOperation(value="员工CURD-分页列表查询", notes="员工CURD-分页列表查询")
@GetMapping(value = "/list")
public Result<?> queryPageList(EmployeeVo employee,
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
HttpServletRequest req) {
//QueryGenerator.initQueryWrapper是jeecg-boot封装的查询,默认支持所有复杂的检索查询
QueryWrapper<EmployeeVo> queryWrapper = QueryGenerator.initQueryWrapper(employee, req.getParameterMap());
Page<EmployeeVo> page = new Page<EmployeeVo>(pageNo, pageSize);
//自定义getAll接口
IPage<EmployeeVo> pageList=employeeService.getAll1(page,queryWrapper);
return Result.ok(pageList);
}
3.servlce
1
2
3
4
5
6
7
8
9
10
|
@Service public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, EmployeeVo> implements IEmployeeService { @Resource private EmployeeMapper employeeMapper; @Override public IPage<EmployeeVo> getAll1(Page<EmployeeVo> page, QueryWrapper<EmployeeVo> queryWrapper) { return employeeMapper.findByPage(page,queryWrapper); } } |
4.mapper.java
public interface EmployeeMapper extends BaseMapper<EmployeeVo> { /** * mybatis-plus多表查询 * @param page * @param wrapper * @return */
//参数加上@Param(Constants.WRAPPER),xml里加上${ew.customSqlSegment}可以实现复杂条件检索查询 IPage<EmployeeVo> findByPage(IPage<EmployeeVo> page, @Param(Constants.WRAPPER) Wrapper<EmployeeVo> wrapper); }
5.mapper.xml
<!--mybatis-plus多表联合查询,带上${ew.customSqlSegment就可以实现查询--> <select id="findByPage" resultType="org.jeecg.modules.demo.employeetest.entity.EmployeeVo"> select employee.*,department.dep_name from employee left join department on employee.sys_org_code = department.id ${ew.customSqlSegment} </select>
6.查询出来的结果
{ "success": true, "message": "操作成功!", "code": 200, "result": { "records": [ { "createTime": "2020-10-14 16:35:36", "sex": "女", "name": "helloTest", "updateTime": "2020-10-14 16:41:41", "id": "1316296704307597313", "depName": "研发部",//这个是部门表中的字段,同过两表联查查询出来的 "age": 23, "hobby": "打牌" }, { "createTime": "2020-08-01 16:50:04", "sex": "男", "name": "萨芬", "updateTime": "2020-09-17 16:50:07", "id": "2", "depName": "人事部", "age": 12, "hobby": "阿斯顿" } ], "total": 2, "size": 10, "current": 1, "orders": [], "optimizeCountSql": true, "hitCount": false, "searchCount": true, "pages": 1 }, "timestamp": 1602729521729 }