mybatis-3 icon indicating copy to clipboard operation
mybatis-3 copied to clipboard

paging query

Open KimHu01 opened this issue 3 years ago • 4 comments

Feature request

How about defining a new tag to implement paging query? And, to define an Page Object for the method return value.

<select_page id="selectByPage" parameterType="com.*.UserQuery" resultMap="userResultMap">
    <count_sql>
        select count(*) from t_user u where u.age >= #{age}
    </count_sql>
    <query_sql>
        select * from t_user u where u.age >= #{age} order by u.age desc limit #{offset}, #{limit}
    </query_sql>
</select_page>
@Repository
public interface UserMapper {

    /**
     * Paging query
     * 
     * @param query 
     * @return
     */
    Page<UserDO> selectByPage(UserQuery query);
}
@Getter
@Setter
public class Page<T> {

    /**
     * offset
     */
    private int offset;

    /**
     * limit
     */
    private int limit;

    /**
     * total
     */
    private int total;

    /**
     * datas
     */
    private List<T> datas;
}

KimHu01 avatar Jun 02 '21 10:06 KimHu01

@harawata Do you think it is necessary?

KimHu01 avatar Jul 12 '21 02:07 KimHu01

Hello @KimHu01 ,

This does not fit MyBatis design. You should use two independent selects.

harawata avatar Jul 12 '21 05:07 harawata

I hope have offset and limit on Example object. when I generation mybatis mapper

zhangleijie avatar Sep 29 '21 07:09 zhangleijie

Why not try a interceptor like this mysql-mybatis-pagination

flashvayne avatar Mar 14 '22 12:03 flashvayne