mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 01:28:24 +08:00
add MapperUtil.getLongNumber
This commit is contained in:
parent
37392d6916
commit
8245e55dce
@ -645,14 +645,7 @@ public interface BaseMapper<T> {
|
||||
queryWrapper.select(count());
|
||||
}
|
||||
List<Object> objects = selectObjectListByQuery(queryWrapper);
|
||||
Object object = objects == null || objects.isEmpty() ? null : objects.get(0);
|
||||
if (object == null) {
|
||||
return 0;
|
||||
} else if (object instanceof Number) {
|
||||
return ((Number) object).longValue();
|
||||
} else {
|
||||
throw FlexExceptions.wrap("selectCountByQuery error, Can not get number value for queryWrapper: %s", queryWrapper);
|
||||
}
|
||||
return MapperUtil.getLongNumber(objects, queryWrapper);
|
||||
} finally {
|
||||
//fixed https://github.com/mybatis-flex/mybatis-flex/issues/49
|
||||
CPI.setSelectColumns(queryWrapper, selectColumns);
|
||||
|
||||
@ -417,14 +417,7 @@ public interface RowMapper {
|
||||
}
|
||||
|
||||
List<Object> objects = selectObjectListByQuery(schema, tableName, queryWrapper);
|
||||
Object object = objects == null || objects.isEmpty() ? null : objects.get(0);
|
||||
if (object == null) {
|
||||
return 0;
|
||||
} else if (object instanceof Number) {
|
||||
return ((Number) object).longValue();
|
||||
} else {
|
||||
throw FlexExceptions.wrap("selectCountByQuery error, Can not get number value for queryWrapper: %s", queryWrapper);
|
||||
}
|
||||
return MapperUtil.getLongNumber(objects, queryWrapper);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -17,6 +17,7 @@ package com.mybatisflex.core.util;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.mybatisflex.core.constant.SqlConsts;
|
||||
import com.mybatisflex.core.exception.FlexExceptions;
|
||||
import com.mybatisflex.core.field.FieldQuery;
|
||||
import com.mybatisflex.core.field.FieldQueryBuilder;
|
||||
import com.mybatisflex.core.query.*;
|
||||
@ -195,4 +196,15 @@ public class MapperUtil {
|
||||
throw new TooManyResultsException(
|
||||
"Expected one result (or null) to be returned by selectOne(), but found: " + size);
|
||||
}
|
||||
|
||||
public static long getLongNumber(List<Object> objects,QueryWrapper queryWrapper){
|
||||
Object object = objects == null || objects.isEmpty() ? null : objects.get(0);
|
||||
if (object == null) {
|
||||
return 0;
|
||||
} else if (object instanceof Number) {
|
||||
return ((Number) object).longValue();
|
||||
} else {
|
||||
throw FlexExceptions.wrap("selectCountByQuery error, Can not get number value for queryWrapper: %s", queryWrapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user