|
@@ -95,7 +95,11 @@ public class PaginationInterceptor implements Interceptor {
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
- * <p> 禁用内存分页 </p> <p> 内存分页会查询所有结果出来处理(这个很吓人的),如果结果变化频繁这个数据还会不准。
|
|
|
+ * <p>
|
|
|
+ * 禁用内存分页
|
|
|
+ * </p>
|
|
|
+ * <p>
|
|
|
+ * 内存分页会查询所有结果出来处理(这个很吓人的),如果结果变化频繁这个数据还会不准。
|
|
|
* </p>
|
|
|
*/
|
|
|
BoundSql boundSql = (BoundSql) metaStatementHandler.getValue("delegate.boundSql");
|
|
@@ -123,21 +127,21 @@ public class PaginationInterceptor implements Interceptor {
|
|
|
StringBuffer countSql = new StringBuffer("SELECT COUNT(1) AS TOTAL ");
|
|
|
if (page.isOptimizeCount()) {
|
|
|
String tempSql = originalSql.replaceAll("(?i)ORDER[\\s]+BY", "ORDER BY");
|
|
|
- String indexOfSql = originalSql.toUpperCase();
|
|
|
+ String indexOfSql = tempSql.toUpperCase();
|
|
|
if (!indexOfSql.contains("DISTINCT")) {
|
|
|
int formIndex = indexOfSql.indexOf("FROM");
|
|
|
int orderByIndex = indexOfSql.lastIndexOf("ORDER BY");
|
|
|
if (formIndex > -1) {
|
|
|
// 无排序情况处理
|
|
|
if (orderByIndex > -1) {
|
|
|
- tempSql = originalSql.substring(0, orderByIndex);
|
|
|
+ tempSql = tempSql.substring(0, orderByIndex);
|
|
|
countSql.append(tempSql.substring(formIndex));
|
|
|
orderBy = false;
|
|
|
} else {
|
|
|
- countSql.append(originalSql.substring(formIndex));
|
|
|
+ countSql.append(tempSql.substring(formIndex));
|
|
|
}
|
|
|
} else {
|
|
|
- countSql.append("FROM (").append(tempSql).append(") A");
|
|
|
+ countSql.append("FROM (").append(originalSql).append(") A");
|
|
|
}
|
|
|
} else {
|
|
|
countSql.append("FROM (").append(originalSql).append(") A");
|