Commit 94cf000f authored by yanzg's avatar yanzg

修改实例化关系

parent d3ed698b
...@@ -502,42 +502,51 @@ public abstract class BaseDaoSql { ...@@ -502,42 +502,51 @@ public abstract class BaseDaoSql {
* @return 查询的结果 * @return 查询的结果
*/ */
public <T extends Object> PageSizeData<T> queryPage(Class<T> cls, PageSizeReqVo pageSize, String sqlName, Object model, QueryPara queryPara) { public <T extends Object> PageSizeData<T> queryPage(Class<T> cls, PageSizeReqVo pageSize, String sqlName, Object model, QueryPara queryPara) {
// 获取需要执行的SQL语句
SqlData from = this.getSql(sqlName);
// 设置基本参数值
PageSizeData<T> data = new PageSizeData<T>(); PageSizeData<T> data = new PageSizeData<T>();
data.setPageIndex(pageSize.getPageIndex()); data.setPageIndex(pageSize.getPageIndex());
data.setPageSize(pageSize.getPageSize()); data.setPageSize(pageSize.getPageSize());
// 设置基本参数值
{
// 获取需要执行的SQL语句
SqlData from = this.getSql(sqlName);
// 对SQL语句进行分页处理 // 对SQL语句进行分页处理
SqlData to = from.copy(); SqlData to = from.copy();
to = getSqlQueryPara(to, queryPara, false); to = getSqlQueryPara(to, queryPara, false);
to.addCode("{LIMIT}", " LIMIT " + pageSize.getPageStart() + "," + pageSize.getPageSize()); to.addCode("{LIMIT}", " LIMIT " + pageSize.getPageStart() + "," + pageSize.getPageSize());
// 按照分页查询数据 // 按照分页查询数据
List<Object> paras = new ArrayList<Object>(); List<Object> baseParas = new ArrayList<Object>();
String sql = this.getQueryPara(paras, to, model); String sql = this.getQueryPara(baseParas, to, model);
// 查询实体数据 // 查询实体数据
List<T> list = this.queryWithCache(cls, sqlName, sql, paras.toArray()); List<T> list = this.queryWithCache(cls, sqlName, sql, baseParas.toArray());
data.setList(list); data.setList(list);
}
// 查询分页总条数的SQL语句
String sqlTo = sql;
// 获取分页查询的SQL语句 // 获取分页查询的SQL语句
{
SqlData fromPageSize = getSql(sqlName + TableSqlCache.PAGE_SIZE_TAG, false); SqlData fromPageSize = getSql(sqlName + TableSqlCache.PAGE_SIZE_TAG, false);
if (fromPageSize != null) { if (fromPageSize == null) {
sqlTo = getQueryPara(new ArrayList<>(), fromPageSize, model); // 获取需要执行的SQL语句
fromPageSize = this.getSql(sqlName);
} }
sqlTo = sqlTo.trim(); fromPageSize = fromPageSize.copy();
// 按照分页查询数据
List<Object> baseParas = new ArrayList<Object>();
String sql = this.getQueryPara(baseParas, fromPageSize, model);
sql = sql.trim();
// 查询总数据量 // 查询总数据量
String sqlSize = "SELECT COUNT(1) FROM (" + String sqlSize = "SELECT COUNT(1) FROM (" +
// 去掉最后一个order by // 去掉最后一个order by
sqlTo.replaceAll("(?i)(ORDER\\s+BY\\s+[^)]+){0,1}(limit\\s+\\d+,\\d+\\s*){0,1}$", "") sql.replaceAll("(?i)(ORDER\\s+BY\\s+[^)]+){0,1}(limit\\s+\\d+,\\d+\\s*){0,1}$", "")
// 去掉第一个 SELECT a.* // 去掉第一个 SELECT a.*
.replaceAll("(^SELECT)\\s+a\\.\\*", "$1 1 AS __id") .replaceAll("(^SELECT)\\s+a\\.\\*", "$1 1 AS __id")
+ ") t"; + ") t";
data.setPageTotal(StringHelper.toInt(queryCellWithCache(String.format("%s.Size", sqlName), sqlSize, paras.toArray())));
data.setPageTotal(StringHelper.toInt(queryCellWithCache(String.format("%s.Size", sqlName), sqlSize, baseParas.toArray())));
}
return data; return data;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment