zoukankan      html  css  js  c++  java
  • 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

    @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
    }

     

  • 相关阅读:
    ABP文档
    ABP框架没有httpPost,httpget,httpput特性
    使用命令关闭占用80端口的程序
    nginx安装编译详解
    docker端口映射设置
    centos6.3安装nginx
    process有个env属性,env属性就是环境变量,里面可以访问到NODE_ENV;NODE_ENV是在启动nodejs时添加上去的;
    使用nssm在windows服务器上部署nodejs
    对象相等与不相等
    可用的CSS文字两端对齐
  • 原文地址:https://www.cnblogs.com/huoyz/p/13819179.html
Copyright © 2011-2022 走看看