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)
|
* 【cache 】 CacheObj默认方法改为protected(issue#I3RIEI@Gitee)
|
||||||
* 【core 】 FileUtil.isEmpty不存在时返回true(issue#1582@Github)
|
* 【core 】 FileUtil.isEmpty不存在时返回true(issue#1582@Github)
|
||||||
* 【core 】 PhoneUtil增加中国澳门和中国台湾手机号校检方法(pr#331@Gitee)
|
* 【core 】 PhoneUtil增加中国澳门和中国台湾手机号校检方法(pr#331@Gitee)
|
||||||
|
* 【db 】 分页查询,自定义sql查询,添加参数(pr#332@Gitee)
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【core 】 修复XmlUtil中omitXmlDeclaration参数无效问题(issue#1581@Github)
|
* 【core 】 修复XmlUtil中omitXmlDeclaration参数无效问题(issue#1581@Github)
|
||||||
|
@ -673,6 +673,7 @@ public abstract class AbstractDb implements Serializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 结果的条目数
|
* 结果的条目数
|
||||||
|
*
|
||||||
* @param sql sql构造器
|
* @param sql sql构造器
|
||||||
* @return 复合条件的结果数
|
* @return 复合条件的结果数
|
||||||
* @throws SQLException SQL执行异常
|
* @throws SQLException SQL执行异常
|
||||||
@ -681,7 +682,7 @@ public abstract class AbstractDb implements Serializable {
|
|||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
return runner.count(conn, sql.build(),sql.getParamValueArray());
|
return runner.count(conn, sql.build(), sql.getParamValueArray());
|
||||||
} finally {
|
} finally {
|
||||||
this.closeConnection(conn);
|
this.closeConnection(conn);
|
||||||
}
|
}
|
||||||
@ -689,31 +690,18 @@ 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 selectSql 查询SQL语句
|
||||||
* @param params 查询参数
|
* @param params 查询参数
|
||||||
* @return 复合条件的结果数
|
* @return 复合条件的结果数
|
||||||
* @throws SQLException SQL执行异常
|
* @throws SQLException SQL执行异常
|
||||||
|
* @since 5.6.6
|
||||||
*/
|
*/
|
||||||
public long count(CharSequence selectSql,Object ...params) throws SQLException {
|
public long count(CharSequence selectSql, Object... params) throws SQLException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
return runner.count(conn, selectSql,params);
|
return runner.count(conn, selectSql, params);
|
||||||
} finally {
|
} finally {
|
||||||
this.closeConnection(conn);
|
this.closeConnection(conn);
|
||||||
}
|
}
|
||||||
@ -833,31 +821,12 @@ public abstract class AbstractDb implements Serializable {
|
|||||||
* @param sql SQL构建器,可以使用{@link SqlBuilder#of(CharSequence)} 包装普通SQL
|
* @param sql SQL构建器,可以使用{@link SqlBuilder#of(CharSequence)} 包装普通SQL
|
||||||
* @param page 分页对象
|
* @param page 分页对象
|
||||||
* @param rsh 结果集处理对象
|
* @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 参数
|
* @param params 参数
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws SQLException SQL执行异常
|
* @throws SQLException SQL执行异常
|
||||||
|
* @since 5.6.6
|
||||||
*/
|
*/
|
||||||
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;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
@ -869,10 +838,11 @@ public abstract class AbstractDb implements Serializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询
|
* 分页查询
|
||||||
|
*
|
||||||
* @param sql SQL构建器
|
* @param sql SQL构建器
|
||||||
* @param page 分页对象
|
* @param page 分页对象
|
||||||
* @param rsh 结果集处理对象
|
* @param rsh 结果集处理对象
|
||||||
* @return: 结果对象
|
* @return 结果对象
|
||||||
* @throws SQLException SQL执行异常
|
* @throws SQLException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public <T> T page(SqlBuilder sql, Page page, RsHandler<T> rsh) throws SQLException {
|
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 sql SQL语句字符串
|
||||||
* @param page 分页对象
|
* @param page 分页对象
|
||||||
* @return 结果对象
|
* @return 结果对象
|
||||||
* @throws SQLException SQL执行异常
|
* @throws SQLException SQL执行异常
|
||||||
* @since 5.5.3
|
* @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;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
|
@ -280,18 +280,6 @@ public class SqlConnRunner extends DialectRunner {
|
|||||||
return findAll(conn, Entity.create(tableName).set(field, values));
|
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
|
* 获取查询结果总数,生成类似于 SELECT count(1) from (sql) as _count
|
||||||
*
|
*
|
||||||
@ -300,11 +288,12 @@ public class SqlConnRunner extends DialectRunner {
|
|||||||
* @param params 查询参数
|
* @param params 查询参数
|
||||||
* @return 结果数
|
* @return 结果数
|
||||||
* @throws SQLException SQL异常
|
* @throws SQLException SQL异常
|
||||||
|
* @since 5.6.6
|
||||||
*/
|
*/
|
||||||
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!");
|
Assert.notBlank(selectSql, "Select SQL must be not blank!");
|
||||||
final int orderByIndex = StrUtil.indexOfIgnoreCase(selectSql, " order by");
|
final int orderByIndex = StrUtil.indexOfIgnoreCase(selectSql, " order by");
|
||||||
if(orderByIndex > 0){
|
if (orderByIndex > 0) {
|
||||||
selectSql = StrUtil.subPre(selectSql, orderByIndex);
|
selectSql = StrUtil.subPre(selectSql, orderByIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user