diff --git a/build.gradle b/build.gradle index 6c880f4..f298e4a 100644 --- a/build.gradle +++ b/build.gradle @@ -55,7 +55,7 @@ uploadArchives { authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD) } pom.project { - version '2.1.3' + version '2.1.6' artifactId ARTIFACT_Id groupId GROUP_ID packaging TYPE diff --git a/src/main/java/com/taover/repository/CustomJdbcTemplate.java b/src/main/java/com/taover/repository/CustomJdbcTemplate.java index d281f5f..5fa31a2 100644 --- a/src/main/java/com/taover/repository/CustomJdbcTemplate.java +++ b/src/main/java/com/taover/repository/CustomJdbcTemplate.java @@ -601,11 +601,24 @@ public class CustomJdbcTemplate { } public Map getPageData(String coreSql, String orderByPartSql, Integer page, Integer pageSize){ + int fromIndex = coreSql.toUpperCase().indexOf("FROM"); + String selectSql = ""; + String fromAndWhereSql = ""; + if(fromIndex > -1) { + selectSql = coreSql.substring(0, fromIndex); + fromAndWhereSql = coreSql.substring(fromIndex, coreSql.length()); + }else { + return UtilsSql.createPage(page, pageSize, 0, new ArrayList()); + } + return this.getPageData(selectSql, fromAndWhereSql, orderByPartSql, page, pageSize); + } + + public Map getPageData(String selectSql, String fromAndWhereSql, String orderByPartSql, Integer page, Integer pageSize){ //构造查询语句 - String querySql = coreSql+orderByPartSql+UtilsSql.getLimitCondition(page, pageSize); + String querySql = selectSql+" "+fromAndWhereSql+" "+orderByPartSql+" "+UtilsSql.getLimitCondition(page, pageSize); //构造统计计数语句 - String countSql = "select count(*) rows from ("+coreSql+" ) t "; + String countSql = "select count(*) rows from ( select 1 "+fromAndWhereSql+" ) t "; //执行查询 List> queryData = new ArrayList>(); @@ -616,11 +629,24 @@ public class CustomJdbcTemplate { } public Map getBeanPageData(String coreSql, String orderByPartSql, Integer page, Integer pageSize, Class beanClass){ + int fromIndex = coreSql.toUpperCase().indexOf("FROM"); + String selectSql = ""; + String fromAndWhereSql = ""; + if(fromIndex > -1) { + selectSql = coreSql.substring(0, fromIndex); + fromAndWhereSql = coreSql.substring(fromIndex, coreSql.length()); + }else { + return UtilsSql.createPage(page, pageSize, 0, new ArrayList()); + } + return this.getPageData(selectSql, fromAndWhereSql, orderByPartSql, page, pageSize, beanClass); + } + + public Map getPageData(String selectSql, String fromAndWhereSql, String orderByPartSql, Integer page, Integer pageSize, Class beanClass){ //构造查询语句 - String querySql = coreSql+orderByPartSql+UtilsSql.getLimitCondition(page, pageSize); + String querySql = selectSql+" "+fromAndWhereSql+" "+orderByPartSql+" "+UtilsSql.getLimitCondition(page, pageSize); //构造统计计数语句 - String countSql = "select count(*) rows from ("+coreSql+" ) t "; + String countSql = "select count(*) rows from ( select 1 "+fromAndWhereSql+" ) t "; //执行查询 List queryData = new ArrayList(); -- libgit2 0.21.2