From b3b4ee091a2089d29e4d3956486091080903e6d9 Mon Sep 17 00:00:00 2001 From: Rui Date: Sun, 17 Dec 2023 13:20:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E5=B8=83=202.1.0=20=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 12 ++++++++++- .../autoconfigure/PageHelperProperties.java | 18 ++++++++++++++++- .../PageHelperStandardProperties.java | 20 +++++++++++++++++++ .../mybatis/pagehelper/MyCountSqlParser.java | 15 ++++++++++++++ .../pagehelper/MyOrderBySqlParser.java | 12 +++++++++++ .../pagehelper/SampleMapperApplication.java | 7 +++++++ ...om.github.pagehelper.parser.CountSqlParser | 1 + .../src/main/resources/application.properties | 3 ++- pom.xml | 10 +++++----- 9 files changed, 90 insertions(+), 8 deletions(-) create mode 100644 pagehelper-spring-boot-samples/pagehelper-spring-boot-sample-annotation/src/main/java/tk/mybatis/pagehelper/MyCountSqlParser.java create mode 100644 pagehelper-spring-boot-samples/pagehelper-spring-boot-sample-annotation/src/main/java/tk/mybatis/pagehelper/MyOrderBySqlParser.java create mode 100644 pagehelper-spring-boot-samples/pagehelper-spring-boot-sample-annotation/src/main/resources/META-INF/services/com.github.pagehelper.parser.CountSqlParser diff --git a/README.md b/README.md index dd16cbe..cb5f5a9 100644 --- a/README.md +++ b/README.md @@ -16,10 +16,20 @@ Add the following dependency to your pom.xml: com.github.pagehelper pagehelper-spring-boot-starter - 2.0.0 + 2.1.0 ``` +## v2.1.0 - 2023-12-17 + +- 升级 PageHelper 到 6.1.0,支持异步 count + 等功能,详细查看 [6.1.0](https://github.com/pagehelper/Mybatis-PageHelper/releases/tag/6.1.0) +- 升级 MyBatis 到 3.5.15 +- 升级 springboot 到 2.7.18 +- 新增参数 `orderBySqlParser`,`OrderBySqlParser`改为接口,允许通过`orderBySqlParser`参数替换为自己的实现 +- 新增参数 `sqlServerSqlParser`,`SqlServerSqlParser`改为接口,允许通过`sqlServerSqlParser`参数替换为自己的实现 +- 接口 `CountSqlParser`,`OrderBySqlParser`,`SqlServerSqlParser` 还支持SPI方式覆盖默认实现,优先级低于参数指定 + ## v2.0.0 - 2023-11-05 - 升级 PageHelper 到 6.0.0,支持异步 count 等功能,详细查看 [6.0](https://github.com/pagehelper/Mybatis-PageHelper/releases/tag/v6.0.0) diff --git a/pagehelper-spring-boot-autoconfigure/src/main/java/com/github/pagehelper/autoconfigure/PageHelperProperties.java b/pagehelper-spring-boot-autoconfigure/src/main/java/com/github/pagehelper/autoconfigure/PageHelperProperties.java index 9a09adf..74f856a 100644 --- a/pagehelper-spring-boot-autoconfigure/src/main/java/com/github/pagehelper/autoconfigure/PageHelperProperties.java +++ b/pagehelper-spring-boot-autoconfigure/src/main/java/com/github/pagehelper/autoconfigure/PageHelperProperties.java @@ -157,11 +157,27 @@ public void setAsyncCount(Boolean asyncCount) { setProperty("asyncCount", asyncCount.toString()); } - public String getCountSqlParser(String countSqlParser) { + public String getCountSqlParser() { return getProperty("countSqlParser"); } public void setCountSqlParser(String countSqlParser) { setProperty("countSqlParser", countSqlParser); } + + public String getOrderBySqlParser() { + return getProperty("orderBySqlParser"); + } + + public void setOrderBySqlParser(String orderBySqlParser) { + setProperty("orderBySqlParser", orderBySqlParser); + } + + public String getSqlServerSqlParser() { + return getProperty("sqlServerSqlParser"); + } + + public void setSqlServerSqlParser(String sqlServerSqlParser) { + setProperty("sqlServerSqlParser", sqlServerSqlParser); + } } diff --git a/pagehelper-spring-boot-autoconfigure/src/main/java/com/github/pagehelper/autoconfigure/PageHelperStandardProperties.java b/pagehelper-spring-boot-autoconfigure/src/main/java/com/github/pagehelper/autoconfigure/PageHelperStandardProperties.java index 3d28a8f..711e8fd 100644 --- a/pagehelper-spring-boot-autoconfigure/src/main/java/com/github/pagehelper/autoconfigure/PageHelperStandardProperties.java +++ b/pagehelper-spring-boot-autoconfigure/src/main/java/com/github/pagehelper/autoconfigure/PageHelperStandardProperties.java @@ -46,6 +46,8 @@ public class PageHelperStandardProperties { private String sqlParser; private Boolean asyncCount; private String countSqlParser; + private String orderBySqlParser; + private String sqlServerSqlParser; @Autowired public PageHelperStandardProperties(PageHelperProperties properties) { @@ -271,4 +273,22 @@ public void setCountSqlParser(String countSqlParser) { this.countSqlParser = countSqlParser; Optional.ofNullable(countSqlParser).ifPresent(v -> properties.setProperty("countSqlParser", v)); } + + public String getOrderBySqlParser() { + return orderBySqlParser; + } + + public void setOrderBySqlParser(String orderBySqlParser) { + this.orderBySqlParser = orderBySqlParser; + Optional.ofNullable(orderBySqlParser).ifPresent(v -> properties.setProperty("orderBySqlParser", v)); + } + + public String getSqlServerSqlParser() { + return sqlServerSqlParser; + } + + public void setSqlServerSqlParser(String sqlServerSqlParser) { + this.sqlServerSqlParser = sqlServerSqlParser; + Optional.ofNullable(sqlServerSqlParser).ifPresent(v -> properties.setProperty("sqlServerSqlParser", v)); + } } diff --git a/pagehelper-spring-boot-samples/pagehelper-spring-boot-sample-annotation/src/main/java/tk/mybatis/pagehelper/MyCountSqlParser.java b/pagehelper-spring-boot-samples/pagehelper-spring-boot-sample-annotation/src/main/java/tk/mybatis/pagehelper/MyCountSqlParser.java new file mode 100644 index 0000000..f1b68d1 --- /dev/null +++ b/pagehelper-spring-boot-samples/pagehelper-spring-boot-sample-annotation/src/main/java/tk/mybatis/pagehelper/MyCountSqlParser.java @@ -0,0 +1,15 @@ +package tk.mybatis.pagehelper; + +import com.github.pagehelper.parser.defaults.DefaultCountSqlParser; + +public class MyCountSqlParser extends DefaultCountSqlParser { + @Override + public String getSmartCountSql(String sql, String countColumn) { + return "/* count */" + super.getSmartCountSql(sql, countColumn); + } + + @Override + public String getSimpleCountSql(String sql) { + return "/* count */" + super.getSimpleCountSql(sql); + } +} diff --git a/pagehelper-spring-boot-samples/pagehelper-spring-boot-sample-annotation/src/main/java/tk/mybatis/pagehelper/MyOrderBySqlParser.java b/pagehelper-spring-boot-samples/pagehelper-spring-boot-sample-annotation/src/main/java/tk/mybatis/pagehelper/MyOrderBySqlParser.java new file mode 100644 index 0000000..de358ab --- /dev/null +++ b/pagehelper-spring-boot-samples/pagehelper-spring-boot-sample-annotation/src/main/java/tk/mybatis/pagehelper/MyOrderBySqlParser.java @@ -0,0 +1,12 @@ +package tk.mybatis.pagehelper; + +import com.github.pagehelper.parser.defaults.DefaultOrderBySqlParser; + +public class MyOrderBySqlParser extends DefaultOrderBySqlParser { + + @Override + public String converToOrderBySql(String sql, String orderBy) { + return "/* order-by */" + super.converToOrderBySql(sql, orderBy); + } + +} diff --git a/pagehelper-spring-boot-samples/pagehelper-spring-boot-sample-annotation/src/main/java/tk/mybatis/pagehelper/SampleMapperApplication.java b/pagehelper-spring-boot-samples/pagehelper-spring-boot-sample-annotation/src/main/java/tk/mybatis/pagehelper/SampleMapperApplication.java index d453aac..4e92268 100644 --- a/pagehelper-spring-boot-samples/pagehelper-spring-boot-sample-annotation/src/main/java/tk/mybatis/pagehelper/SampleMapperApplication.java +++ b/pagehelper-spring-boot-samples/pagehelper-spring-boot-sample-annotation/src/main/java/tk/mybatis/pagehelper/SampleMapperApplication.java @@ -57,6 +57,13 @@ public void run(String... args) throws Exception { System.out.println("Name: " + user.getName()); } + PageHelper.orderBy("id desc"); + users = userMapper.findAll(); + System.out.println("Total: " + ((Page) users).getTotal()); + for (User user : users) { + System.out.println("Name: " + user.getName()); + } + PageRowBounds rowBounds = new PageRowBounds(3, 5); users = userMapper.findAll(rowBounds); System.out.println("Total: " + rowBounds.getTotal()); diff --git a/pagehelper-spring-boot-samples/pagehelper-spring-boot-sample-annotation/src/main/resources/META-INF/services/com.github.pagehelper.parser.CountSqlParser b/pagehelper-spring-boot-samples/pagehelper-spring-boot-sample-annotation/src/main/resources/META-INF/services/com.github.pagehelper.parser.CountSqlParser new file mode 100644 index 0000000..fcc6e94 --- /dev/null +++ b/pagehelper-spring-boot-samples/pagehelper-spring-boot-sample-annotation/src/main/resources/META-INF/services/com.github.pagehelper.parser.CountSqlParser @@ -0,0 +1 @@ +tk.mybatis.pagehelper.MyCountSqlParser \ No newline at end of file diff --git a/pagehelper-spring-boot-samples/pagehelper-spring-boot-sample-annotation/src/main/resources/application.properties b/pagehelper-spring-boot-samples/pagehelper-spring-boot-sample-annotation/src/main/resources/application.properties index 3acba05..ff0f1e7 100644 --- a/pagehelper-spring-boot-samples/pagehelper-spring-boot-sample-annotation/src/main/resources/application.properties +++ b/pagehelper-spring-boot-samples/pagehelper-spring-boot-sample-annotation/src/main/resources/application.properties @@ -33,4 +33,5 @@ pagehelper.hello=\u4F60\u597D pagehelper.nihao=Hello pagehelper.offset-as-page-num=true pagehelper.count-column=* -pagehelper.async-count=true \ No newline at end of file +pagehelper.async-count=true +pagehelper.orderBySqlParser=tk.mybatis.pagehelper.MyOrderBySqlParser \ No newline at end of file diff --git a/pom.xml b/pom.xml index 31c8ada..cdd2897 100644 --- a/pom.xml +++ b/pom.xml @@ -63,17 +63,17 @@ - 2.0.0 + 2.1.0 8 8 UTF-8 UTF-8 - 3.5.14 - 6.0.0 - 2.3.1 - 2.7.17 + 3.5.15 + 6.1.0 + 2.3.2 + 2.7.18