mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add param support for count and page
This commit is contained in:
parent
7a006515a5
commit
74a1cb2c68
@ -12,6 +12,7 @@
|
||||
* 【cache 】 CacheObj默认方法改为protected(issue#I3RIEI@Gitee)
|
||||
* 【core 】 FileUtil.isEmpty不存在时返回true(issue#1582@Github)
|
||||
* 【core 】 PhoneUtil增加中国澳门和中国台湾手机号校检方法(pr#331@Gitee)
|
||||
* 【db 】 分页查询,自定义sql查询,添加参数(pr#332@Gitee)
|
||||
|
||||
### 🐞Bug修复
|
||||
* 【core 】 修复XmlUtil中omitXmlDeclaration参数无效问题(issue#1581@Github)
|
||||
|
@ -673,6 +673,7 @@ public abstract class AbstractDb implements Serializable {
|
||||
|
||||
/**
|
||||
* 结果的条目数
|
||||
*
|
||||
* @param sql sql构造器
|
||||
* @return 复合条件的结果数
|
||||
* @throws SQLException SQL执行异常
|
||||
@ -689,25 +690,12 @@ public abstract class AbstractDb implements Serializable {
|
||||
|
||||
/**
|
||||
* 结果的条目数
|
||||
* @param selectSql 查询SQL语句
|
||||
* @return 复合条件的结果数
|
||||
* @throws SQLException SQL执行异常
|
||||
*/
|
||||
public long count(CharSequence selectSql) 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执行异常
|
||||
* @since 5.6.6
|
||||
*/
|
||||
public long count(CharSequence selectSql, Object... params) throws SQLException {
|
||||
Connection conn = null;
|
||||
@ -833,29 +821,10 @@ public abstract class AbstractDb implements Serializable {
|
||||
* @param sql SQL构建器,可以使用{@link SqlBuilder#of(CharSequence)} 包装普通SQL
|
||||
* @param page 分页对象
|
||||
* @param rsh 结果集处理对象
|
||||
* @return 结果对象
|
||||
* @throws SQLException SQL执行异常
|
||||
* @since 5.5.3
|
||||
*/
|
||||
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执行异常
|
||||
* @since 5.6.6
|
||||
*/
|
||||
public <T> T page(CharSequence sql, Page page, RsHandler<T> rsh, Object... params) throws SQLException {
|
||||
Connection conn = null;
|
||||
@ -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,6 +876,7 @@ public abstract class AbstractDb implements Serializable {
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param sql SQL语句字符串
|
||||
* @param page 分页对象
|
||||
* @return 结果对象
|
||||
|
@ -280,18 +280,6 @@ public class SqlConnRunner extends DialectRunner {
|
||||
return findAll(conn, Entity.create(tableName).set(field, values));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取查询结果总数,生成类似于 SELECT count(1) from (sql) as _count
|
||||
*
|
||||
* @param conn 数据库连接对象
|
||||
* @param selectSql 查询语句
|
||||
* @return 结果数
|
||||
* @throws SQLException SQL异常
|
||||
*/
|
||||
public long count(Connection conn, CharSequence selectSql) throws SQLException {
|
||||
return this.count(conn,selectSql,null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取查询结果总数,生成类似于 SELECT count(1) from (sql) as _count
|
||||
*
|
||||
@ -300,6 +288,7 @@ public class SqlConnRunner extends DialectRunner {
|
||||
* @param params 查询参数
|
||||
* @return 结果数
|
||||
* @throws SQLException SQL异常
|
||||
* @since 5.6.6
|
||||
*/
|
||||
public long count(Connection conn, CharSequence selectSql, Object... params) throws SQLException {
|
||||
Assert.notBlank(selectSql, "Select SQL must be not blank!");
|
||||
|
Loading…
x
Reference in New Issue
Block a user