Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

提供自定义分页的能力 #45

Open
wayshall opened this issue Apr 1, 2022 · 1 comment
Open

提供自定义分页的能力 #45

wayshall opened this issue Apr 1, 2022 · 1 comment

Comments

@wayshall
Copy link
Owner

wayshall commented Apr 1, 2022

现在的分页只能使用dbm内置的自动生成limit sql的方式分页。
有时候需要自定义分页,比如left join一对多查询分页时,这种自动分页的方式通常都是错的。

wayshall added a commit that referenced this issue Apr 1, 2022
1、通过@query注解提供关闭关闭自动生成limit sql的特性;
2、即使关闭limit sql时,仍然会把内置命名参数:DbmQueryFirstResult,
:DbmQueryMaxResult 传递进sql上下文内作为分页参数

fix #45
@wayshall
Copy link
Owner Author

wayshall commented Apr 1, 2022

可通过@query注解关闭自动生成limit sql

@Query(useAutoLimitSqlIfPagination=false)
    Page<LotteryJoinerResponse> findJoinerWihtResouceListPage(Page<LotteryJoinerResponse> toPage, GetJoinerPageRequest request);

在sql文件里,自定义分页……

/**
 * @name: findJoinerWihtResouceListPage
 */
select 
    t.*,
    li.title as lottery_name,
    res.res_path as res_value
 from (
    SELECT
            lj.id,
            lj.draw_count,
            lj.`status`,
            lj.joiner_address,
            lj.joiner_id,
            lj.joiner_user_name,
            lj.joiner_nick_name,
            lj.joiner_mobile,
            lj.joiner_head_url,
            lj.lottery_id
    FROM
            lottery_joiner lj
    WHERE
            lj.lottery_id = 100
    ORDER BY
            lj.update_at
limit :DbmQueryFirstResult, :DbmQueryMaxResult
) t 
    LEFT JOIN lottery_info li ON t.lottery_id = li.id
        left JOIN cm_resource res on res.biz_id = t.id

/**
 * @name: findJoinerWihtResouceListPage
 * @property: countSql
 */
    SELECT
        count(1)
    FROM
        lottery_joiner lj
    WHERE
        lj.lottery_id =  :request.lotteryId

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant