From 255dd3cd5742b1a0a9b70d79a380bdbcaa422b9f Mon Sep 17 00:00:00 2001 From: lvshuyan <81841267@qq.com> Date: Tue, 20 Nov 2018 17:41:02 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E5=85=BC=E5=AE=B9sharding-jdbc=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E8=87=AA=E5=8A=A8=E5=88=86=E8=A1=A8=E5=88=86=E9=A1=B5?= =?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD=EF=BC=8C=E7=9B=AE=E5=89=8D=E5=8F=AA?= =?UTF-8?q?=E8=80=83=E8=99=91=E4=BA=86sqlserver=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=EF=BC=8C=E5=85=B6=E4=BB=96=E7=9A=84=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E5=8F=AF=E6=8C=89=E7=85=A7=E7=9B=B8=E5=90=8C=E6=80=9D=E8=B7=AF?= =?UTF-8?q?=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dialect/helper/SqlServerDialect.java | 42 +++++++++++++++++-- .../pagehelper/parser/CountSqlParser.java | 4 +- .../pagehelper/parser/SqlServerParser.java | 37 ++++++++++------ .../github/pagehelper/util/ExecutorUtil.java | 22 +++++++--- 4 files changed, 82 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/github/pagehelper/dialect/helper/SqlServerDialect.java b/src/main/java/com/github/pagehelper/dialect/helper/SqlServerDialect.java index c27923c..ca76094 100644 --- a/src/main/java/com/github/pagehelper/dialect/helper/SqlServerDialect.java +++ b/src/main/java/com/github/pagehelper/dialect/helper/SqlServerDialect.java @@ -37,8 +37,10 @@ import com.github.pagehelper.util.StringUtil; import org.apache.ibatis.cache.CacheKey; import org.apache.ibatis.mapping.BoundSql; import org.apache.ibatis.mapping.MappedStatement; +import org.apache.ibatis.mapping.ParameterMapping; import org.apache.ibatis.session.RowBounds; +import java.util.List; import java.util.Map; import java.util.Properties; @@ -50,6 +52,9 @@ public class SqlServerDialect extends AbstractHelperDialect { protected Cache CACHE_COUNTSQL; protected Cache CACHE_PAGESQL; protected ReplaceSql replaceSql; + private static final String PARAM_START_ROW = "startRow"; + private static final String PARAM_END_ROW = "endRow"; + private static final String PARAM_REPLACE_WORD = "?"; @Override public String getCountSql(MappedStatement ms, BoundSql boundSql, Object parameterObject, RowBounds rowBounds, CacheKey countKey) { @@ -72,6 +77,15 @@ public class SqlServerDialect extends AbstractHelperDialect { return paramMap; } + /** + * 这里分页参数不能写死,写死的话不能被sharding-jdbc解析 + * 需要改成动态参数,所以将参数替换成? + * update by lvshuyan + * @param sql + * @param page + * @param pageKey + * @return + */ @Override public String getPageSql(String sql, Page page, CacheKey pageKey) { //处理pageKey @@ -85,8 +99,8 @@ public class SqlServerDialect extends AbstractHelperDialect { cacheSql = replaceSql.restore(cacheSql); CACHE_PAGESQL.put(sql, cacheSql); } - cacheSql = cacheSql.replace(String.valueOf(Long.MIN_VALUE), String.valueOf(page.getStartRow())); - cacheSql = cacheSql.replace(String.valueOf(Long.MAX_VALUE), String.valueOf(page.getPageSize())); + cacheSql = cacheSql.replace(String.valueOf(Long.MIN_VALUE), PARAM_REPLACE_WORD); + cacheSql = cacheSql.replace(String.valueOf(Long.MAX_VALUE), PARAM_REPLACE_WORD); return cacheSql; } @@ -109,7 +123,29 @@ public class SqlServerDialect extends AbstractHelperDialect { sql = this.replaceSql.restore(sql); } - return page.isOrderByOnly() ? sql : this.getPageSql(sql, page, pageKey); + if(page.isOrderByOnly()){ + return sql; + }else{ + //生成分页SQL,并将分页参数替换为? + sql = this.getPageSql(sql, page, pageKey); + //将分页参数设置到parameter + int startRow = page.getStartRow(); + int pageSize = page.getPageSize(); + int endRow = startRow + pageSize; + + //设置动态参数的对应mapping + List parameterMappingList = boundSql.getParameterMappings(); + + //设置起始和终止参数 + ParameterMapping startRowMapping = new ParameterMapping.Builder(ms.getConfiguration(), PARAM_START_ROW, int.class).build(); + ParameterMapping endRowMapping = new ParameterMapping.Builder(ms.getConfiguration(), PARAM_END_ROW, int.class).build(); + parameterMappingList.add(startRowMapping); + parameterMappingList.add(endRowMapping); + + boundSql.setAdditionalParameter(PARAM_START_ROW, startRow); + boundSql.setAdditionalParameter(PARAM_END_ROW, endRow); + return sql; + } } @Override diff --git a/src/main/java/com/github/pagehelper/parser/CountSqlParser.java b/src/main/java/com/github/pagehelper/parser/CountSqlParser.java index a15c8da..addd909 100644 --- a/src/main/java/com/github/pagehelper/parser/CountSqlParser.java +++ b/src/main/java/com/github/pagehelper/parser/CountSqlParser.java @@ -227,14 +227,14 @@ public class CountSqlParser { /** * 将sql转换为count查询 - * + * 高版本的SQLSERVER必须要有别名 add by lvshuyan * @param select */ public void sqlToCount(Select select, String name) { SelectBody selectBody = select.getSelectBody(); // 是否能简化count查询 List COUNT_ITEM = new ArrayList(); - COUNT_ITEM.add(new SelectExpressionItem(new Column("count(" + name +")"))); + COUNT_ITEM.add(new SelectExpressionItem(new Column("count(" + name + ") totalCount"))); if (selectBody instanceof PlainSelect && isSimpleCount((PlainSelect) selectBody)) { ((PlainSelect) selectBody).setSelectItems(COUNT_ITEM); } else { diff --git a/src/main/java/com/github/pagehelper/parser/SqlServerParser.java b/src/main/java/com/github/pagehelper/parser/SqlServerParser.java index 3abe586..80c9ee1 100644 --- a/src/main/java/com/github/pagehelper/parser/SqlServerParser.java +++ b/src/main/java/com/github/pagehelper/parser/SqlServerParser.java @@ -28,7 +28,9 @@ import com.github.pagehelper.PageException; import net.sf.jsqlparser.expression.Alias; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.LongValue; +import net.sf.jsqlparser.expression.operators.conditional.AndExpression; import net.sf.jsqlparser.expression.operators.relational.GreaterThan; +import net.sf.jsqlparser.expression.operators.relational.MinorThanEquals; import net.sf.jsqlparser.parser.CCJSqlParserUtil; import net.sf.jsqlparser.schema.Column; import net.sf.jsqlparser.statement.Statement; @@ -122,6 +124,9 @@ public class SqlServerParser { /** * 获取一个外层包装的TOP查询 + * 因为sharding-jdbc不支持top解析,为了兼容sharding-jdbc + * 改造分页SQL,不使用top,改成使用page_number>startRow and page_number<=endRow + * update by lvshuyan * * @param select * @return @@ -156,29 +161,35 @@ public class SqlServerParser { fromInnerItem.setAlias(PAGE_TABLE_ALIAS); innerSelectBody.setFromItem(fromInnerItem); - //新建一个select Select newSelect = new Select(); PlainSelect newSelectBody = new PlainSelect(); - //设置top - Top top = new Top(); - top.setExpression(new LongValue(Long.MAX_VALUE)); - newSelectBody.setTop(top); - //设置order by - List orderByElements = new ArrayList(); + + //排序 + List orderByElements = new ArrayList(); OrderByElement orderByElement = new OrderByElement(); orderByElement.setExpression(PAGE_ROW_NUMBER_COLUMN); orderByElements.add(orderByElement); newSelectBody.setOrderByElements(orderByElements); - //设置where + + //分页条件 GreaterThan greaterThan = new GreaterThan(); greaterThan.setLeftExpression(PAGE_ROW_NUMBER_COLUMN); - greaterThan.setRightExpression(new LongValue(Long.MIN_VALUE)); - newSelectBody.setWhere(greaterThan); - //设置selectItems + greaterThan.setRightExpression(new LongValue(START_ROW)); + + MinorThanEquals minorThanEquals = new MinorThanEquals(); + minorThanEquals.setLeftExpression(PAGE_ROW_NUMBER_COLUMN); + minorThanEquals.setRightExpression(new LongValue(PAGE_SIZE)); + + //设置where + AndExpression andExpression = new AndExpression(greaterThan, minorThanEquals); + newSelectBody.setWhere(andExpression); + + //设置列 newSelectBody.setSelectItems(selectItems); - //设置fromIterm + + //内部 SQL SubSelect fromItem = new SubSelect(); - fromItem.setSelectBody(innerSelectBody); //中层子查询 + fromItem.setSelectBody(innerSelectBody); fromItem.setAlias(PAGE_TABLE_ALIAS); newSelectBody.setFromItem(fromItem); diff --git a/src/main/java/com/github/pagehelper/util/ExecutorUtil.java b/src/main/java/com/github/pagehelper/util/ExecutorUtil.java index 4fc3050..f79d924 100644 --- a/src/main/java/com/github/pagehelper/util/ExecutorUtil.java +++ b/src/main/java/com/github/pagehelper/util/ExecutorUtil.java @@ -30,12 +30,14 @@ import org.apache.ibatis.cache.CacheKey; import org.apache.ibatis.executor.Executor; import org.apache.ibatis.mapping.BoundSql; import org.apache.ibatis.mapping.MappedStatement; +import org.apache.ibatis.mapping.ParameterMapping; import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.RowBounds; import java.lang.reflect.Field; import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -164,14 +166,24 @@ public abstract class ExecutorUtil { CacheKey pageKey = cacheKey; //处理参数对象 parameter = dialect.processParameterObject(ms, parameter, boundSql, pageKey); + //当原SQL的参数为空时,boundSql.getParameterMappings()是一个不可修改的集合,重新new一个BoundSql,解决不能设置分页参数问题 + BoundSql newBoundSql = boundSql; + if(boundSql.getParameterMappings() == null || boundSql.getParameterMappings().size() == 0){ + Map additionalParameters = getAdditionalParameter(boundSql); + newBoundSql = new BoundSql(ms.getConfiguration(), boundSql.getSql(), new ArrayList(), parameter); + for(String key : additionalParameters.keySet()){ + newBoundSql.setAdditionalParameter(key, additionalParameters.get(key)); + } + } + //调用方言获取分页 sql - String pageSql = dialect.getPageSql(ms, boundSql, parameter, rowBounds, pageKey); - BoundSql pageBoundSql = new BoundSql(ms.getConfiguration(), pageSql, boundSql.getParameterMappings(), parameter); + String pageSql = dialect.getPageSql(ms, newBoundSql, parameter, rowBounds, pageKey); + BoundSql pageBoundSql = new BoundSql(ms.getConfiguration(), pageSql, newBoundSql.getParameterMappings(), parameter); - Map additionalParameters = getAdditionalParameter(boundSql); + Map newAdditionalParameters = getAdditionalParameter(newBoundSql); //设置动态参数 - for (String key : additionalParameters.keySet()) { - pageBoundSql.setAdditionalParameter(key, additionalParameters.get(key)); + for (String key : newAdditionalParameters.keySet()) { + pageBoundSql.setAdditionalParameter(key, newAdditionalParameters.get(key)); } //执行分页查询 return executor.query(ms, parameter, RowBounds.DEFAULT, resultHandler, pageKey, pageBoundSql); -- Gitee From 54765ef1055788dc998d44f809b6cfc15b1be6cb Mon Sep 17 00:00:00 2001 From: lvshuyan <81841267@qq.com> Date: Tue, 20 Nov 2018 17:53:15 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=96=B9=E5=BC=8F=EF=BC=8C=E5=8F=82=E8=80=83?= =?UTF-8?q?MySqlDialect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dialect/helper/SqlServerDialect.java | 51 +++++++++---------- .../github/pagehelper/util/ExecutorUtil.java | 20 ++------ 2 files changed, 28 insertions(+), 43 deletions(-) diff --git a/src/main/java/com/github/pagehelper/dialect/helper/SqlServerDialect.java b/src/main/java/com/github/pagehelper/dialect/helper/SqlServerDialect.java index ca76094..99e9ef7 100644 --- a/src/main/java/com/github/pagehelper/dialect/helper/SqlServerDialect.java +++ b/src/main/java/com/github/pagehelper/dialect/helper/SqlServerDialect.java @@ -33,13 +33,16 @@ import com.github.pagehelper.dialect.replace.RegexWithNolockReplaceSql; import com.github.pagehelper.dialect.replace.SimpleWithNolockReplaceSql; import com.github.pagehelper.parser.OrderByParser; import com.github.pagehelper.parser.SqlServerParser; +import com.github.pagehelper.util.MetaObjectUtil; import com.github.pagehelper.util.StringUtil; import org.apache.ibatis.cache.CacheKey; import org.apache.ibatis.mapping.BoundSql; import org.apache.ibatis.mapping.MappedStatement; import org.apache.ibatis.mapping.ParameterMapping; +import org.apache.ibatis.reflection.MetaObject; import org.apache.ibatis.session.RowBounds; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Properties; @@ -52,9 +55,6 @@ public class SqlServerDialect extends AbstractHelperDialect { protected Cache CACHE_COUNTSQL; protected Cache CACHE_PAGESQL; protected ReplaceSql replaceSql; - private static final String PARAM_START_ROW = "startRow"; - private static final String PARAM_END_ROW = "endRow"; - private static final String PARAM_REPLACE_WORD = "?"; @Override public String getCountSql(MappedStatement ms, BoundSql boundSql, Object parameterObject, RowBounds rowBounds, CacheKey countKey) { @@ -74,6 +74,23 @@ public class SqlServerDialect extends AbstractHelperDialect { @Override public Object processPageParameter(MappedStatement ms, Map paramMap, Page page, BoundSql boundSql, CacheKey pageKey) { + paramMap.put(PAGEPARAMETER_FIRST, page.getStartRow()); + paramMap.put(PAGEPARAMETER_SECOND, page.getPageSize()); + //处理pageKey + pageKey.update(page.getStartRow()); + pageKey.update(page.getPageSize()); + //处理参数配置 + if (boundSql.getParameterMappings() != null) { + List newParameterMappings = new ArrayList(boundSql.getParameterMappings()); + if (page.getStartRow() == 0) { + newParameterMappings.add(new ParameterMapping.Builder(ms.getConfiguration(), PAGEPARAMETER_SECOND, Integer.class).build()); + } else { + newParameterMappings.add(new ParameterMapping.Builder(ms.getConfiguration(), PAGEPARAMETER_FIRST, Integer.class).build()); + newParameterMappings.add(new ParameterMapping.Builder(ms.getConfiguration(), PAGEPARAMETER_SECOND, Integer.class).build()); + } + MetaObject metaObject = MetaObjectUtil.forObject(boundSql); + metaObject.setValue("parameterMappings", newParameterMappings); + } return paramMap; } @@ -99,8 +116,8 @@ public class SqlServerDialect extends AbstractHelperDialect { cacheSql = replaceSql.restore(cacheSql); CACHE_PAGESQL.put(sql, cacheSql); } - cacheSql = cacheSql.replace(String.valueOf(Long.MIN_VALUE), PARAM_REPLACE_WORD); - cacheSql = cacheSql.replace(String.valueOf(Long.MAX_VALUE), PARAM_REPLACE_WORD); + cacheSql = cacheSql.replace(String.valueOf(Long.MIN_VALUE), "?"); + cacheSql = cacheSql.replace(String.valueOf(Long.MAX_VALUE), "?"); return cacheSql; } @@ -123,29 +140,7 @@ public class SqlServerDialect extends AbstractHelperDialect { sql = this.replaceSql.restore(sql); } - if(page.isOrderByOnly()){ - return sql; - }else{ - //生成分页SQL,并将分页参数替换为? - sql = this.getPageSql(sql, page, pageKey); - //将分页参数设置到parameter - int startRow = page.getStartRow(); - int pageSize = page.getPageSize(); - int endRow = startRow + pageSize; - - //设置动态参数的对应mapping - List parameterMappingList = boundSql.getParameterMappings(); - - //设置起始和终止参数 - ParameterMapping startRowMapping = new ParameterMapping.Builder(ms.getConfiguration(), PARAM_START_ROW, int.class).build(); - ParameterMapping endRowMapping = new ParameterMapping.Builder(ms.getConfiguration(), PARAM_END_ROW, int.class).build(); - parameterMappingList.add(startRowMapping); - parameterMappingList.add(endRowMapping); - - boundSql.setAdditionalParameter(PARAM_START_ROW, startRow); - boundSql.setAdditionalParameter(PARAM_END_ROW, endRow); - return sql; - } + return page.isOrderByOnly() ? sql : this.getPageSql(sql, page, pageKey); } @Override diff --git a/src/main/java/com/github/pagehelper/util/ExecutorUtil.java b/src/main/java/com/github/pagehelper/util/ExecutorUtil.java index f79d924..89fea1a 100644 --- a/src/main/java/com/github/pagehelper/util/ExecutorUtil.java +++ b/src/main/java/com/github/pagehelper/util/ExecutorUtil.java @@ -166,24 +166,14 @@ public abstract class ExecutorUtil { CacheKey pageKey = cacheKey; //处理参数对象 parameter = dialect.processParameterObject(ms, parameter, boundSql, pageKey); - //当原SQL的参数为空时,boundSql.getParameterMappings()是一个不可修改的集合,重新new一个BoundSql,解决不能设置分页参数问题 - BoundSql newBoundSql = boundSql; - if(boundSql.getParameterMappings() == null || boundSql.getParameterMappings().size() == 0){ - Map additionalParameters = getAdditionalParameter(boundSql); - newBoundSql = new BoundSql(ms.getConfiguration(), boundSql.getSql(), new ArrayList(), parameter); - for(String key : additionalParameters.keySet()){ - newBoundSql.setAdditionalParameter(key, additionalParameters.get(key)); - } - } - //调用方言获取分页 sql - String pageSql = dialect.getPageSql(ms, newBoundSql, parameter, rowBounds, pageKey); - BoundSql pageBoundSql = new BoundSql(ms.getConfiguration(), pageSql, newBoundSql.getParameterMappings(), parameter); + String pageSql = dialect.getPageSql(ms, boundSql, parameter, rowBounds, pageKey); + BoundSql pageBoundSql = new BoundSql(ms.getConfiguration(), pageSql, boundSql.getParameterMappings(), parameter); - Map newAdditionalParameters = getAdditionalParameter(newBoundSql); + Map additionalParameters = getAdditionalParameter(boundSql); //设置动态参数 - for (String key : newAdditionalParameters.keySet()) { - pageBoundSql.setAdditionalParameter(key, newAdditionalParameters.get(key)); + for (String key : additionalParameters.keySet()) { + pageBoundSql.setAdditionalParameter(key, additionalParameters.get(key)); } //执行分页查询 return executor.query(ms, parameter, RowBounds.DEFAULT, resultHandler, pageKey, pageBoundSql); -- Gitee From 8f5f153a510deb003eb9afa00fe33b28f545854f Mon Sep 17 00:00:00 2001 From: lvshuyan <81841267@qq.com> Date: Tue, 20 Nov 2018 17:58:38 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=96=B9=E5=BC=8F=EF=BC=8C=E5=8F=82=E8=80=83?= =?UTF-8?q?OracleDialect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dialect/helper/SqlServerDialect.java | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/github/pagehelper/dialect/helper/SqlServerDialect.java b/src/main/java/com/github/pagehelper/dialect/helper/SqlServerDialect.java index 99e9ef7..8691bb3 100644 --- a/src/main/java/com/github/pagehelper/dialect/helper/SqlServerDialect.java +++ b/src/main/java/com/github/pagehelper/dialect/helper/SqlServerDialect.java @@ -74,23 +74,15 @@ public class SqlServerDialect extends AbstractHelperDialect { @Override public Object processPageParameter(MappedStatement ms, Map paramMap, Page page, BoundSql boundSql, CacheKey pageKey) { - paramMap.put(PAGEPARAMETER_FIRST, page.getStartRow()); - paramMap.put(PAGEPARAMETER_SECOND, page.getPageSize()); + int startRow = page.getStartRow(); + int endRow = startRow + page.getPageSize(); + paramMap.put(PAGEPARAMETER_FIRST, startRow); + paramMap.put(PAGEPARAMETER_SECOND, endRow); //处理pageKey - pageKey.update(page.getStartRow()); - pageKey.update(page.getPageSize()); + pageKey.update(startRow); + pageKey.update(endRow); //处理参数配置 - if (boundSql.getParameterMappings() != null) { - List newParameterMappings = new ArrayList(boundSql.getParameterMappings()); - if (page.getStartRow() == 0) { - newParameterMappings.add(new ParameterMapping.Builder(ms.getConfiguration(), PAGEPARAMETER_SECOND, Integer.class).build()); - } else { - newParameterMappings.add(new ParameterMapping.Builder(ms.getConfiguration(), PAGEPARAMETER_FIRST, Integer.class).build()); - newParameterMappings.add(new ParameterMapping.Builder(ms.getConfiguration(), PAGEPARAMETER_SECOND, Integer.class).build()); - } - MetaObject metaObject = MetaObjectUtil.forObject(boundSql); - metaObject.setValue("parameterMappings", newParameterMappings); - } + handleParameter(boundSql, ms); return paramMap; } -- Gitee From cd7def89b362cdcb2c055ddfcc84da62e9070c17 Mon Sep 17 00:00:00 2001 From: lvshuyan <81841267@qq.com> Date: Tue, 20 Nov 2018 18:08:20 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../github/pagehelper/dialect/helper/SqlServerDialect.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/java/com/github/pagehelper/dialect/helper/SqlServerDialect.java b/src/main/java/com/github/pagehelper/dialect/helper/SqlServerDialect.java index 8691bb3..825a0d6 100644 --- a/src/main/java/com/github/pagehelper/dialect/helper/SqlServerDialect.java +++ b/src/main/java/com/github/pagehelper/dialect/helper/SqlServerDialect.java @@ -33,17 +33,12 @@ import com.github.pagehelper.dialect.replace.RegexWithNolockReplaceSql; import com.github.pagehelper.dialect.replace.SimpleWithNolockReplaceSql; import com.github.pagehelper.parser.OrderByParser; import com.github.pagehelper.parser.SqlServerParser; -import com.github.pagehelper.util.MetaObjectUtil; import com.github.pagehelper.util.StringUtil; import org.apache.ibatis.cache.CacheKey; import org.apache.ibatis.mapping.BoundSql; import org.apache.ibatis.mapping.MappedStatement; -import org.apache.ibatis.mapping.ParameterMapping; -import org.apache.ibatis.reflection.MetaObject; import org.apache.ibatis.session.RowBounds; -import java.util.ArrayList; -import java.util.List; import java.util.Map; import java.util.Properties; -- Gitee From 941e2ec667202969afb671a95313f3142d5f3063 Mon Sep 17 00:00:00 2001 From: lvshuyan <81841267@qq.com> Date: Tue, 20 Nov 2018 18:34:48 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/github/pagehelper/util/ExecutorUtil.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/github/pagehelper/util/ExecutorUtil.java b/src/main/java/com/github/pagehelper/util/ExecutorUtil.java index 89fea1a..4fc3050 100644 --- a/src/main/java/com/github/pagehelper/util/ExecutorUtil.java +++ b/src/main/java/com/github/pagehelper/util/ExecutorUtil.java @@ -30,14 +30,12 @@ import org.apache.ibatis.cache.CacheKey; import org.apache.ibatis.executor.Executor; import org.apache.ibatis.mapping.BoundSql; import org.apache.ibatis.mapping.MappedStatement; -import org.apache.ibatis.mapping.ParameterMapping; import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.RowBounds; import java.lang.reflect.Field; import java.sql.SQLException; -import java.util.ArrayList; import java.util.List; import java.util.Map; -- Gitee From 3d42d0f0a96447e968b8b621452540803e9d26d5 Mon Sep 17 00:00:00 2001 From: lvshuyan <81841267@qq.com> Date: Wed, 21 Nov 2018 10:44:42 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pagehelper/dialect/helper/SqlServerDialect.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/github/pagehelper/dialect/helper/SqlServerDialect.java b/src/main/java/com/github/pagehelper/dialect/helper/SqlServerDialect.java index 825a0d6..48e5dcc 100644 --- a/src/main/java/com/github/pagehelper/dialect/helper/SqlServerDialect.java +++ b/src/main/java/com/github/pagehelper/dialect/helper/SqlServerDialect.java @@ -69,13 +69,11 @@ public class SqlServerDialect extends AbstractHelperDialect { @Override public Object processPageParameter(MappedStatement ms, Map paramMap, Page page, BoundSql boundSql, CacheKey pageKey) { - int startRow = page.getStartRow(); - int endRow = startRow + page.getPageSize(); - paramMap.put(PAGEPARAMETER_FIRST, startRow); - paramMap.put(PAGEPARAMETER_SECOND, endRow); + paramMap.put(PAGEPARAMETER_FIRST, page.getStartRow()); + paramMap.put(PAGEPARAMETER_SECOND, page.getEndRow()); //处理pageKey - pageKey.update(startRow); - pageKey.update(endRow); + pageKey.update(page.getStartRow()); + pageKey.update(page.getEndRow()); //处理参数配置 handleParameter(boundSql, ms); return paramMap; @@ -92,9 +90,6 @@ public class SqlServerDialect extends AbstractHelperDialect { */ @Override public String getPageSql(String sql, Page page, CacheKey pageKey) { - //处理pageKey - pageKey.update(page.getStartRow()); - pageKey.update(page.getPageSize()); String cacheSql = CACHE_PAGESQL.get(sql); if (cacheSql == null) { cacheSql = sql; -- Gitee