springboot+mybatis-plus 自定义分页+条件构造器+xml自定义sql的使用

1、在mapper.java中定义一个方法,如:

IPage<MembershipYearCalendar> getPageList(Page<MembershipYearCalendar> page, @Param(Constants.WRAPPER) Wrapper<MembershipYearCalendar> queryWrapper);

其中page是分页对象,返回的也必须是IPage类型,queryWrapper为条件构造对象
2、在mapper.xml中定义sql语句,如:

 <select id="getPageList" resultMap="BaseMap">
     SELECT t.* FROM
         (
             SELECT
             t.id,
             t.NAME,
             t.enterprise,
             t.belong_to_people,
             CASE
                     WHEN t1.service_count IS NULL THEN
                     0 ELSE t1.service_count
                 END service_count,
          (SELECT matter FROM member_matter m where m.member_of_the_pool_id=t.id order by create_date desc limit 0,1) matter,
       (SELECT service_date FROM member_matter m where m.member_of_the_pool_id=t.id order by create_date desc limit 0,1) service_date,
       (SELECT create_date FROM member_matter m where m.member_of_the_pool_id=t.id order by create_date desc limit 0,1) create_date,
       (SELECT commit_name FROM member_matter m where m.member_of_the_pool_id=t.id order by create_date desc limit 0,1) commit_name
             FROM member_of_the_pool t
             LEFT JOIN ( SELECT member_of_the_pool_id, count(*) service_count FROM member_matter GROUP BY member_of_the_pool_id ) t1 ON t.id = t1.member_of_the_pool_id
         ) t ${ew.customSqlSegment}
    select>

其中最重要的是${ew.customSqlSegment},它表示条件构造器,此时返回的就是一个分好页的列表。

你可能感兴趣的:(spring,boot,xml,sql)