mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add param support for count and page
This commit is contained in:
@@ -673,6 +673,7 @@ public abstract class AbstractDb implements Serializable {
|
||||
|
||||
/**
|
||||
* 结果的条目数
|
||||
*
|
||||
* @param sql sql构造器
|
||||
* @return 复合条件的结果数
|
||||
* @throws SQLException SQL执行异常
|
||||
@@ -681,7 +682,7 @@ public abstract class AbstractDb implements Serializable {
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
return runner.count(conn, sql.build(),sql.getParamValueArray());
|
||||
return runner.count(conn, sql.build(), sql.getParamValueArray());
|
||||
} finally {
|
||||
this.closeConnection(conn);
|
||||
}
|
||||
@@ -689,31 +690,18 @@ public abstract class AbstractDb implements Serializable {
|
||||
|
||||
/**
|
||||
* 结果的条目数
|
||||
*
|
||||
* @param selectSql 查询SQL语句
|
||||
* @param params 查询参数
|
||||
* @return 复合条件的结果数
|
||||
* @throws SQLException SQL执行异常
|
||||
* @since 5.6.6
|
||||
*/
|
||||
public long count(CharSequence selectSql) throws SQLException {
|
||||
public long count(CharSequence selectSql, Object... params) throws SQLException {
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
return runner.count(conn, selectSql);
|
||||
} finally {
|
||||
this.closeConnection(conn);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 结果的条目数
|
||||
* @param selectSql 查询SQL语句
|
||||
* @param params 查询参数
|
||||
* @return 复合条件的结果数
|
||||
* @throws SQLException SQL执行异常
|
||||
*/
|
||||
public long count(CharSequence selectSql,Object ...params) throws SQLException {
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
return runner.count(conn, selectSql,params);
|
||||
return runner.count(conn, selectSql, params);
|
||||
} finally {
|
||||
this.closeConnection(conn);
|
||||
}
|
||||
@@ -829,35 +817,16 @@ public abstract class AbstractDb implements Serializable {
|
||||
/**
|
||||
* 分页查询<br>
|
||||
*
|
||||
* @param <T> 结果对象类型
|
||||
* @param sql SQL构建器,可以使用{@link SqlBuilder#of(CharSequence)} 包装普通SQL
|
||||
* @param page 分页对象
|
||||
* @param rsh 结果集处理对象
|
||||
* @param <T> 结果对象类型
|
||||
* @param sql SQL构建器,可以使用{@link SqlBuilder#of(CharSequence)} 包装普通SQL
|
||||
* @param page 分页对象
|
||||
* @param rsh 结果集处理对象
|
||||
* @param params 参数
|
||||
* @return 结果对象
|
||||
* @throws SQLException SQL执行异常
|
||||
* @since 5.5.3
|
||||
* @since 5.6.6
|
||||
*/
|
||||
public <T> T page(CharSequence sql, Page page, RsHandler<T> rsh) throws SQLException {
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
return runner.page(conn, SqlBuilder.of(sql), page, rsh);
|
||||
} finally {
|
||||
this.closeConnection(conn);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询<br>
|
||||
* @param <T> 结果对象类型
|
||||
* @param sql SQL构建器,可以使用{@link SqlBuilder#of(CharSequence)} 包装普通SQL
|
||||
* @param page 分页对象
|
||||
* @param rsh 结果集处理对象
|
||||
* @param params 参数
|
||||
* @return 结果对象
|
||||
* @throws SQLException SQL执行异常
|
||||
*/
|
||||
public <T> T page(CharSequence sql, Page page, RsHandler<T> rsh,Object ...params) throws SQLException {
|
||||
public <T> T page(CharSequence sql, Page page, RsHandler<T> rsh, Object... params) throws SQLException {
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
@@ -869,10 +838,11 @@ public abstract class AbstractDb implements Serializable {
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param sql SQL构建器
|
||||
* @param page 分页对象
|
||||
* @param rsh 结果集处理对象
|
||||
* @return: 结果对象
|
||||
* @return 结果对象
|
||||
* @throws SQLException SQL执行异常
|
||||
*/
|
||||
public <T> T page(SqlBuilder sql, Page page, RsHandler<T> rsh) throws SQLException {
|
||||
@@ -906,13 +876,14 @@ public abstract class AbstractDb implements Serializable {
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param sql SQL语句字符串
|
||||
* @param page 分页对象
|
||||
* @return 结果对象
|
||||
* @throws SQLException SQL执行异常
|
||||
* @since 5.5.3
|
||||
*/
|
||||
public PageResult<Entity> page(CharSequence sql, Page page ,Object ...params) throws SQLException {
|
||||
public PageResult<Entity> page(CharSequence sql, Page page, Object... params) throws SQLException {
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
|
@@ -285,26 +285,15 @@ public class SqlConnRunner extends DialectRunner {
|
||||
*
|
||||
* @param conn 数据库连接对象
|
||||
* @param selectSql 查询语句
|
||||
* @param params 查询参数
|
||||
* @return 结果数
|
||||
* @throws SQLException SQL异常
|
||||
* @since 5.6.6
|
||||
*/
|
||||
public long count(Connection conn, CharSequence selectSql) throws SQLException {
|
||||
return this.count(conn,selectSql,null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取查询结果总数,生成类似于 SELECT count(1) from (sql) as _count
|
||||
*
|
||||
* @param conn 数据库连接对象
|
||||
* @param selectSql 查询语句
|
||||
* @param params 查询参数
|
||||
* @return 结果数
|
||||
* @throws SQLException SQL异常
|
||||
*/
|
||||
public long count(Connection conn, CharSequence selectSql,Object ...params) throws SQLException {
|
||||
public long count(Connection conn, CharSequence selectSql, Object... params) throws SQLException {
|
||||
Assert.notBlank(selectSql, "Select SQL must be not blank!");
|
||||
final int orderByIndex = StrUtil.indexOfIgnoreCase(selectSql, " order by");
|
||||
if(orderByIndex > 0){
|
||||
if (orderByIndex > 0) {
|
||||
selectSql = StrUtil.subPre(selectSql, orderByIndex);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user