Commit 4631c60c1e611af9920cce1def972be7c816762a

Authored by wangbin
1 parent 94117321

1.optimized query func

@@ -55,7 +55,7 @@ uploadArchives { @@ -55,7 +55,7 @@ uploadArchives {
55 authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD) 55 authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD)
56 } 56 }
57 pom.project { 57 pom.project {
58 - version '2.1.3' 58 + version '2.1.6'
59 artifactId ARTIFACT_Id 59 artifactId ARTIFACT_Id
60 groupId GROUP_ID 60 groupId GROUP_ID
61 packaging TYPE 61 packaging TYPE
src/main/java/com/taover/repository/CustomJdbcTemplate.java
@@ -601,11 +601,24 @@ public class CustomJdbcTemplate<T, ID extends Serializable> { @@ -601,11 +601,24 @@ public class CustomJdbcTemplate<T, ID extends Serializable> {
601 } 601 }
602 602
603 public Map<String, Object> getPageData(String coreSql, String orderByPartSql, Integer page, Integer pageSize){ 603 public Map<String, Object> getPageData(String coreSql, String orderByPartSql, Integer page, Integer pageSize){
  604 + int fromIndex = coreSql.toUpperCase().indexOf("FROM");
  605 + String selectSql = "";
  606 + String fromAndWhereSql = "";
  607 + if(fromIndex > -1) {
  608 + selectSql = coreSql.substring(0, fromIndex);
  609 + fromAndWhereSql = coreSql.substring(fromIndex, coreSql.length());
  610 + }else {
  611 + return UtilsSql.createPage(page, pageSize, 0, new ArrayList<Object>());
  612 + }
  613 + return this.getPageData(selectSql, fromAndWhereSql, orderByPartSql, page, pageSize);
  614 + }
  615 +
  616 + public Map<String, Object> getPageData(String selectSql, String fromAndWhereSql, String orderByPartSql, Integer page, Integer pageSize){
604 //构造查询语句 617 //构造查询语句
605 - String querySql = coreSql+orderByPartSql+UtilsSql.getLimitCondition(page, pageSize); 618 + String querySql = selectSql+" "+fromAndWhereSql+" "+orderByPartSql+" "+UtilsSql.getLimitCondition(page, pageSize);
606 619
607 //构造统计计数语句 620 //构造统计计数语句
608 - String countSql = "select count(*) rows from ("+coreSql+" ) t "; 621 + String countSql = "select count(*) rows from ( select 1 "+fromAndWhereSql+" ) t ";
609 622
610 //执行查询 623 //执行查询
611 List<Map<String, Object>> queryData = new ArrayList<Map<String, Object>>(); 624 List<Map<String, Object>> queryData = new ArrayList<Map<String, Object>>();
@@ -616,11 +629,24 @@ public class CustomJdbcTemplate&lt;T, ID extends Serializable&gt; { @@ -616,11 +629,24 @@ public class CustomJdbcTemplate&lt;T, ID extends Serializable&gt; {
616 } 629 }
617 630
618 public <E> Map<String, Object> getBeanPageData(String coreSql, String orderByPartSql, Integer page, Integer pageSize, Class<E> beanClass){ 631 public <E> Map<String, Object> getBeanPageData(String coreSql, String orderByPartSql, Integer page, Integer pageSize, Class<E> beanClass){
  632 + int fromIndex = coreSql.toUpperCase().indexOf("FROM");
  633 + String selectSql = "";
  634 + String fromAndWhereSql = "";
  635 + if(fromIndex > -1) {
  636 + selectSql = coreSql.substring(0, fromIndex);
  637 + fromAndWhereSql = coreSql.substring(fromIndex, coreSql.length());
  638 + }else {
  639 + return UtilsSql.createPage(page, pageSize, 0, new ArrayList<Object>());
  640 + }
  641 + return this.getPageData(selectSql, fromAndWhereSql, orderByPartSql, page, pageSize, beanClass);
  642 + }
  643 +
  644 + public <E> Map<String, Object> getPageData(String selectSql, String fromAndWhereSql, String orderByPartSql, Integer page, Integer pageSize, Class<E> beanClass){
619 //构造查询语句 645 //构造查询语句
620 - String querySql = coreSql+orderByPartSql+UtilsSql.getLimitCondition(page, pageSize); 646 + String querySql = selectSql+" "+fromAndWhereSql+" "+orderByPartSql+" "+UtilsSql.getLimitCondition(page, pageSize);
621 647
622 //构造统计计数语句 648 //构造统计计数语句
623 - String countSql = "select count(*) rows from ("+coreSql+" ) t "; 649 + String countSql = "select count(*) rows from ( select 1 "+fromAndWhereSql+" ) t ";
624 650
625 //执行查询 651 //执行查询
626 List<E> queryData = new ArrayList<E>(); 652 List<E> queryData = new ArrayList<E>();