mybatis插件PageHelper分页查询结果为实体内嵌套集合时处理办法

现状: 有两张表

采集摄像头图片记录表 snap_report_record  (关键字段:id、total_num采集总数、success_num成功数、fail_num失败数)

采集图片失败摄像头表 snap_report_fail_camera  (关键字段:report_record_id 采集摄像头图片记录表关联ID、camera_name摄像头名称)

需求:前端需要分页查询采集摄像头图片记录,点击失败记录查看失败的详情

实现方式:

使用mybatis分页插件

java代码如下:

public CompletableFuture<PageInfo<JobExecuResultVo>> queryJobReport(JobReportQuery jobReportQuery) {
        CompletableFuture<PageInfo<JobExecuResultVo>> future = CompletableFuture.supplyAsync(() -> {
            PageHelper.startPage(jobReportQuery.getPageNum(), jobReportQuery.getPageSize());
            List<JobExecuResultVo> list = snapReportRecordMapper.queryRecord(jobReportQuery);
            PageInfo<JobExecuResultVo> pageInfo = new PageInfo<>(list);
            return pageInfo;
        });
        return future;
    }

mybatis xml如下:

主要利用了mybatis子查询标签collection

  <resultMap id="ReportRecord" type="com.linkcm.smart.center.bean.vo.JobExecuResultVo">
    <result property="id" column="id"/>
    <result property="jobName" column="job_name"/>
    <result property="successNum" column="success_num"/>
    <result property="totalNum" column="total_num"/>
    <result property="failNum" column="fail_num"/>
    <result property="cubeId" column="cube_id"/>
    <result property="snapTime" column="snap_time"/>
    <result property="jobId" column="job_id"/>
    <collection property="snapFailedCameraVoList" ofType="com.linkcm.smart.center.bean.vo.SnapFailedCameraVo" select="queryFailCamera" column="id" >
    </collection>
  </resultMap>

  <resultMap id="failCamera" type="com.linkcm.smart.center.bean.vo.SnapFailedCameraVo">
    <result property="cameraName" column="camera_name"/>
    <result property="errorMsg" column="error_msg"/>
    <result property="channelIndex" column="channel_index"/>
    <result property="presetName" column="preset_name"/>
    <result property="errorType" column="error_type"/>
  </resultMap>

  <select id="queryFailCamera" resultMap="failCamera" >
     select camera_name , error_msg, preset_name,channel_index, error_type from snap_report_fail_camera f where f.report_record_id = #{id}
  </select>

  <select id="queryRecord" parameterType="com.linkcm.smart.center.bean.query.JobReportQuery"  resultMap="ReportRecord">
    select r.id, r.job_name, r.cube_id ,r.snap_time, r.total_num , r.fail_num, r.success_num,r.job_id from
    snap_report_record r
    <where>
      <if test="jobReportQuery!=null">
        <if test="jobReportQuery.startTime!=null">
          and r.snap_time <![CDATA[ >= #{jobReportQuery.startTime}]]>
        </if>
        <if test="jobReportQuery.endTime!=null">
          and r.snap_time <![CDATA[ <= #{jobReportQuery.endTime}]]>
        </if>
        <if test="jobReportQuery.cubeId!=null">
          and r.cube_id =#{jobReportQuery.cubeId}
        </if>
        <if test="jobReportQuery.jobName!=null and jobReportQuery.jobName!=''">
          and r.job_name like concat('%',#{jobReportQuery.jobName},'%')
        </if>
      </if>
    </where>
    group by r.id
  </select>

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值