mybatisplus自定义xml的sql语句进行自动分页

1、xxxMapper.xml定义

<select id="leftJoinPageList" resultMap="MonitoringDataResult"
        parameterType="com.ktt.carbon.verification.domain.bo.MonitoringDataBo">
    SELECT d.* from carbon_monitoring_data d LEFT JOIN carbon_monitoring_site s on d.site_id=s.id
    <where>
        <if test="bo.siteName != null">
            and site_name like concat('%',#{bo.siteName},'%')
        if>
        <if test="bo.siteNumber != null">
            and site_number like concat('%',#{bo.siteNumber},'%')
        if>
        <if test="bo.siteNumber != null">
            and site_number like concat('%',#{bo.siteNumber},'%')
        if>
    where>
    where s.site_name like "%test1%"
select>

2、xxMapper.xml

/**
 * 左连接站点表分页查询
 */
Page<CarbonMonitoringDataVo> leftJoinPageList(IPage pageQuery, @Param("bo") MonitoringDataBo bo);

3、使用

@Override
public TableDataInfo<MonitoringDataVo> groupByPageList(MonitoringDataBo bo, PageQuery pageQuery) {
    Page<CarbonMonitoringDataVo> carbonMonitoringDataPage = baseMapper.leftJoinPageList(pageQuery.build(), bo);
    List<MonitoringDataVo> records = MonitoringDataPage.getRecords();
    return TableDataInfo.build(carbonMonitoringDataPage);
}

你可能感兴趣的:(mybatis,xml,sql,mybatis-plus)