Browse Source

分页插件countSql fix - 正则表达式调整

storyxc 2 years ago
parent
commit
a50472f5c7

+ 4 - 4
superdesk-libs-mybatis/src/main/java/cn/superdesk/libs/mybatis/plugin/pagination/PageSqlUtils.java

@@ -16,7 +16,7 @@ public class PageSqlUtils {
     private static final String OFFSET_PLACEHOLDER    = "#{offset}";
     private static final String OFFSET_PLACEHOLDER    = "#{offset}";
 
 
     // select 正则
     // select 正则
-    private static final String SQL_SELECT_PATTERN    = "(select|SELECT).*?(?=from|FROM)";
+    private static final String SQL_SELECT_PATTERN    = "(select|SELECT).*?(?=from\\s|FROM\\s)";
 
 
     // order by 正则
     // order by 正则
     private static final String SQL_ORDER_PATTERN     = "(order|ORDER)\\s+(by|BY)";
     private static final String SQL_ORDER_PATTERN     = "(order|ORDER)\\s+(by|BY)";
@@ -70,7 +70,7 @@ public class PageSqlUtils {
 
 
 
 
         /* 样例1 */
         /* 样例1 */
-        String sql = "select a.* from audited_policy a where 1=1 \n\t   \n\t   \n\t   \n\t   \n\t   and title like CONCAT('%',?,'%')   \n\t   \n\t   \n\t   \n\t   \n\t   \n\t   \n\t    \n\t   \n\t  order by updated_at desc";
+        String sql = "select a.*,from_1 from\naudited_policy a where 1=1 \n\t   \n\t   \n\t   \n\t   \n\t   and title like CONCAT('%',?,'%')   \n\t   \n\t   \n\t   \n\t   \n\t   \n\t   \n\t    \n\t   \n\t  order by updated_at desc";
 
 
         System.out.println(">>>>" + getCountSql(sql));
         System.out.println(">>>>" + getCountSql(sql));
         System.out.println(">>>>" + getLimitSQL(DbType.MYSQL, sql, new PageParams()));
         System.out.println(">>>>" + getLimitSQL(DbType.MYSQL, sql, new PageParams()));
@@ -84,8 +84,8 @@ public class PageSqlUtils {
         System.out.println(">>>>" + getLimitSQL(DbType.MYSQL, sql, new PageParams()));
         System.out.println(">>>>" + getLimitSQL(DbType.MYSQL, sql, new PageParams()));
 
 
         /* 样例3 */
         /* 样例3 */
-        sql = "SELECT  u.id as userId,u.name,u.cert_no as idcard,u.mobile,u.verified as userVerified,u.cert_front_url certFrontUrl,u.cert_back_url certBackUrl,  o.salary,o.notax as afterTaxSalary,o.vattax as vatax,o.extratax as surtax,o.incometax,o.tax,o.invfphm as invoiceNo  FROM cbd_invorderdet";
+        sql = "SELECT from_1,u.id as userId,u.name,u.cert_no as idcard,u.mobile,u.verified as userVerified,u.cert_front_url certFrontUrl,u.cert_back_url certBackUrl,  o.salary,o.notax as afterTaxSalary,o.vattax as vatax,o.extratax as surtax,o.incometax,o.tax,o.invfphm as invoiceNo  FROM cbd_invorderdet";
 
 
-        System.out.println(sql.replaceAll("(select|SELECT).*?(?=from|FROM)", SQL_COUNT_PREFIX));
+        System.out.println(sql.replaceAll("(select|SELECT).*?(?=from\\s|FROM\\s)", SQL_COUNT_PREFIX));
     }
     }
 }
 }