mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 17:18:24 +08:00
refactor: 重构 selectCountByQuery 方法。
This commit is contained in:
parent
4f766156ea
commit
55a90424fa
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.mybatisflex.core;
|
package com.mybatisflex.core;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.constant.FuncName;
|
||||||
import com.mybatisflex.core.exception.FlexExceptions;
|
import com.mybatisflex.core.exception.FlexExceptions;
|
||||||
import com.mybatisflex.core.field.FieldQueryBuilder;
|
import com.mybatisflex.core.field.FieldQueryBuilder;
|
||||||
import com.mybatisflex.core.mybatis.MappedStatementTypes;
|
import com.mybatisflex.core.mybatis.MappedStatementTypes;
|
||||||
@ -643,9 +644,15 @@ public interface BaseMapper<T> {
|
|||||||
// 未设置 COUNT(...) 列,默认使用 COUNT(*) 查询
|
// 未设置 COUNT(...) 列,默认使用 COUNT(*) 查询
|
||||||
queryWrapper.select(count());
|
queryWrapper.select(count());
|
||||||
objects = selectObjectListByQuery(queryWrapper);
|
objects = selectObjectListByQuery(queryWrapper);
|
||||||
} else if (selectColumns.get(0) instanceof CountQueryColumn) {
|
} else if (selectColumns.get(0) instanceof FunctionQueryColumn) {
|
||||||
// 自定义 COUNT 函数,COUNT 函数必须在第一列
|
// COUNT 函数必须在第一列
|
||||||
// 可以使用 COUNT(1)、COUNT(列名) 代替默认的 COUNT(*)
|
if (!FuncName.COUNT.equalsIgnoreCase(
|
||||||
|
((FunctionQueryColumn) selectColumns.get(0)).getFnName()
|
||||||
|
)) {
|
||||||
|
// 第一个查询列不是 COUNT 函数,使用 COUNT(*) 替换所有的查询列
|
||||||
|
queryWrapper.select(count());
|
||||||
|
}
|
||||||
|
// 第一个查询列是 COUNT 函数,可以使用 COUNT(1)、COUNT(列名) 代替默认的 COUNT(*)
|
||||||
objects = selectObjectListByQuery(queryWrapper);
|
objects = selectObjectListByQuery(queryWrapper);
|
||||||
} else {
|
} else {
|
||||||
// 查询列中的第一列不是 COUNT 函数
|
// 查询列中的第一列不是 COUNT 函数
|
||||||
@ -748,6 +755,7 @@ public interface BaseMapper<T> {
|
|||||||
* @param queryWrapper 查询条件
|
* @param queryWrapper 查询条件
|
||||||
* @return page 数据
|
* @return page 数据
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
default Page<T> paginate(Page<T> page, QueryWrapper queryWrapper, Consumer<FieldQueryBuilder<T>>... consumers) {
|
default Page<T> paginate(Page<T> page, QueryWrapper queryWrapper, Consumer<FieldQueryBuilder<T>>... consumers) {
|
||||||
return paginateAs(page, queryWrapper, null, consumers);
|
return paginateAs(page, queryWrapper, null, consumers);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user