diff --git a/README.ZH_CN.md b/README.ZH_CN.md
index 42deacd..bee3df9 100644
--- a/README.ZH_CN.md
+++ b/README.ZH_CN.md
@@ -20,14 +20,14 @@ $ mvn clean install
io.leego
mypages
- 1.1.2
+ 2.0.0
```
### Gradle
```xml
-implementation 'io.leego:mypages:1.1.2'
+implementation 'io.leego:mypages:2.0.0'
```
## 数据库
@@ -36,18 +36,18 @@ implementation 'io.leego:mypages:1.1.2'
|:-:|:-:|:-:|:-:|:-:|:-:|
|MySQL|✔|PostgreSQL|✔|Oracle|✔|
|MariaDB|✔|SQLite|✔|DB2|✔|
-|H2|✔|Phoenix|✔|Apache Derby|✔|
+|H2|✔|Apache Phoenix|✔|Apache Derby|✔|
|HyperSQL|✔|Informix|✔|TiDB|✔|
-|SQL Server|✔|Apache Hive|✔|
+|Microsoft SQL Server|✔|Apache Hive|✔|
## 文档
[English Document 英文版](README.md)
-> * [用户指南 (中文版)](docs/USERGUIDE.ZH_CN.md)
-> * [User Guide (English)](docs/USERGUIDE.md)
-> * [mypages-spring-boot-starter (中文版)](docs/STARTER_USERGUIDE.ZH_CN.md)
-> * [mypages-spring-boot-starter (English)](docs/STARTER_USERGUIDE.md)
+> * [用户指南 (中文版)](mypages/README.ZH_CN.md)
+> * [User Guide (English)](mypages/README.md)
+> * [mypages-spring-boot-starter (中文版)](mypages-spring-boot-starter/README.ZH_CN.md)
+> * [mypages-spring-boot-starter (English)](mypages-spring-boot-starter/README.md)
## 交流
diff --git a/README.md b/README.md
index 6866b3d..ed1f2b5 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ Many databases, one plugin.
## Installation
-Please make sure the Java version is 1.8 and above.
+Please make sure the Java version is 1.8 or above.
```bash
$ git clone https://github.com/yihleego/mypages.git
@@ -21,14 +21,14 @@ $ mvn clean install
io.leego
mypages
- 1.1.2
+ 2.0.0
```
### Gradle
```xml
-implementation 'io.leego:mypages:1.1.2'
+implementation 'io.leego:mypages:2.0.0'
```
## Supported
@@ -37,18 +37,18 @@ implementation 'io.leego:mypages:1.1.2'
|:-:|:-:|:-:|:-:|:-:|:-:|
|MySQL|✔|PostgreSQL|✔|Oracle|✔|
|MariaDB|✔|SQLite|✔|DB2|✔|
-|H2|✔|Phoenix|✔|Apache Derby|✔|
+|H2|✔|Apache Phoenix|✔|Apache Derby|✔|
|HyperSQL|✔|Informix|✔|TiDB|✔|
-|SQL Server|✔|Apache Hive|✔|
+|Microsoft SQL Server|✔|Apache Hive|✔|
## Documentation
[Chinese Document 中文版](README.ZH_CN.md)
-> * [User Guide (English)](docs/USERGUIDE.md)
-> * [用户指南 (中文版)](docs/USERGUIDE.ZH_CN.md)
-> * [mypages-spring-boot-starter (English)](docs/STARTER_USERGUIDE.md)
-> * [mypages-spring-boot-starter (中文版)](docs/STARTER_USERGUIDE.ZH_CN.md)
+> * [User Guide (English)](mypages/README.md)
+> * [用户指南 (中文版)](mypages/README.ZH_CN.md)
+> * [mypages-spring-boot-starter (English)](mypages-spring-boot-starter/README.md)
+> * [mypages-spring-boot-starter (中文版)](mypages-spring-boot-starter/README.ZH_CN.md)
## Contact
diff --git a/docs/STARTER_USERGUIDE.ZH_CN.md b/docs/STARTER_USERGUIDE.ZH_CN.md
deleted file mode 100644
index eec92b7..0000000
--- a/docs/STARTER_USERGUIDE.ZH_CN.md
+++ /dev/null
@@ -1,109 +0,0 @@
-# 1. 简介
-
-MyPages是Java实现基于[MyBatis](https://github.com/mybatis/mybatis-3)的开源分页插件,最大程度简化数据库分页查询操作,支持市面上大部分数据库,如:MySQL、PostgreSQL、Oracle、SQLServer等。
-
-# 2. 准备工作
-
-请确保您的Java版本在1.8及以上。
-
-# 3. 依赖
-
-## 3.1 Maven
-
-```xml
-
- io.leego
- mypages-spring-boot-starter
- 1.1.2
-
-```
-
-## 3.2 Gradle
-
-```xml
-implementation 'io.leego:mypages-spring-boot-starter:1.1.2'
-```
-
-# 4. 配置
-
-|Property|Description|
-|:-|:-|
-|spring.mypages.enabled|是否启用mypages。|
-|spring.mypages.sql-dialect|指定sql dialect,如:`MySQL`、`PostgreSQL`、`Oracle`等。|
-|spring.mypages.count-expr|设置count字段名称,默认值为`*`。|
-|spring.mypages.page-field|从参数字段中获取`page`值。|
-|spring.mypages.size-field|从参数字段中获取`size`值。|
-|spring.mypages.offset-field|从参数字段中获取`offset`值。|
-|spring.mypages.rows-field|从参数字段中获取`rows`值。|
-|spring.mypages.count-expr-field|从参数字段中获取count表达式。|
-|spring.mypages.count-method-name-field|从参数字段中获取自定义count方法名称。|
-|spring.mypages.enable-count-field|从参数字段中判断是否启用count。|
-|spring.mypages.skip-query-if-count-equals-zero|是否跳过查询如果结果数量为`0`。|
-|spring.mypages.use-generated-if-count-method-is-missing|是否使用自动生成的count方法如果指定count方法不存在。|
-|spring.mypages.default-page|如果`page`为空或小于`1`,则用`default-page`替换`page`。|
-|spring.mypages.default-size|如果`size`为空或小于`1`,则用`default-size`替换`size`。|
-|spring.mypages.max-page|如果`page`大于`max-page`,则用`max-page`替换`page`。|
-|spring.mypages.max-size|如果`size`大于`max-size`,则用`max-size`替换`size`。|
-
-## 示例
-
-使用分页参数定义一个类,并配置参数字段名。
-
-```java
-public class Pageable {
- private Integer page;
- private Integer size;
- private Integer offset;
- private Integer rows;
- private String countExpr;
- private String countMethodName;
- private Boolean enableCount;
- /* getter setter */
-}
-```
-
-**请注意sql-dialect必须被配置。**
-
-Properties
-
-```properties
-spring.mypages.enabled=true
-spring.mypages.sql-dialect=MYSQL
-spring.mypages.count-expr=*
-spring.mypages.page-field=page
-spring.mypages.size-field=size
-spring.mypages.offset-field=offset
-spring.mypages.rows-field=rows
-spring.mypages.count-expr-field=countExpr
-spring.mypages.count-method-name-field=countMethodName
-spring.mypages.enable-count-field=enableCount
-spring.mypages.skip-query-if-count-equals-zero=true
-spring.mypages.use-generated-if-count-method-is-missing=true
-spring.mypages.default-page=1
-spring.mypages.default-size=10
-spring.mypages.max-page=10000
-spring.mypages.max-size=10000
-```
-
-Yaml
-
-```yaml
-spring:
- mypages:
- enabled: true
- sql-dialect: MYSQL
- count-expr: '*'
- page-field: page
- size-field: size
- offset-field: offset
- rows-field: rows
- count-expr-field: countExpr
- count-method-name-field: countMethodName
- enable-count-field: enableCount
- skip-query-if-count-equals-zero: true
- use-generated-if-count-method-is-missing: true
- default-page: 1
- default-size: 10
- max-page: 10000
- max-size: 10000
-```
\ No newline at end of file
diff --git a/docs/STARTER_USERGUIDE.md b/docs/STARTER_USERGUIDE.md
deleted file mode 100644
index ec12937..0000000
--- a/docs/STARTER_USERGUIDE.md
+++ /dev/null
@@ -1,109 +0,0 @@
-# 1. Introduction
-
-MyPages is a java based, open source pagination plugin for [MyBatis](https://github.com/mybatis/mybatis-3) that simplifies database paging queries.
-
-# 2. Getting Started
-
-Please make sure the Java version is 1.8 and above.
-
-# 3. Dependency
-
-## 3.1 Maven
-
-```xml
-
- io.leego
- mypages-spring-boot-starter
- 1.1.2
-
-```
-
-## 3.2 Gradle
-
-```xml
-implementation 'io.leego:mypages-spring-boot-starter:1.1.2'
-```
-
-# 4. Configuration
-
-|Property|Description|
-|:-|:-|
-|spring.mypages.enabled|Whether to enable mypages.|
-|spring.mypages.sql-dialect|The sql dialect such as `MySQL`, `PostgreSQL`, `Oracle`, etc.|
-|spring.mypages.count-expr|The column name or expression, the default value is `*`.|
-|spring.mypages.page-field|The `page` field name of the parameter.|
-|spring.mypages.size-field|The `size` field name of the parameter.|
-|spring.mypages.offset-field|The `offset` field name of the parameter.|
-|spring.mypages.rows-field|The `rows` field name of the parameter.|
-|spring.mypages.count-expr-field|The count expression field name of the parameter.|
-|spring.mypages.count-method-name-field|The `count-method-name` field name of the parameter.|
-|spring.mypages.enable-count-field|The `enable-count` field name of the parameter.|
-|spring.mypages.skip-query-if-count-equals-zero|Whether to skip query if total value equals zero.|
-|spring.mypages.use-generated-if-count-method-is-missing|Whether to use generated if the specified count method is missing.|
-|spring.mypages.default-page|Replaces the `page` with `default-page` if the `page` is `null` or less than `1`.|
-|spring.mypages.default-size|Replaces the `size` with `default-size` if the `size` is `null` or less than `1`.|
-|spring.mypages.max-page|Replaces the `page` with `max-page` if the `page` is greater than `max-page`.|
-|spring.mypages.max-size|Replaces the `size` with `max-size` if the `size` is greater than `max-size`.|
-
-## For example
-
-Define a class with paging parameters.
-
-```java
-public class Pageable {
- private Integer page;
- private Integer size;
- private Integer offset;
- private Integer rows;
- private String countExpr;
- private String countMethodName;
- private Boolean enableCount;
- /* getter setter */
-}
-```
-
-**Please notice that the sql-dialect is required.**
-
-Properties
-
-```properties
-spring.mypages.enabled=true
-spring.mypages.sql-dialect=MYSQL
-spring.mypages.count-expr=*
-spring.mypages.page-field=page
-spring.mypages.size-field=size
-spring.mypages.offset-field=offset
-spring.mypages.rows-field=rows
-spring.mypages.count-expr-field=countExpr
-spring.mypages.count-method-name-field=countMethodName
-spring.mypages.enable-count-field=enableCount
-spring.mypages.skip-query-if-count-equals-zero=true
-spring.mypages.use-generated-if-count-method-is-missing=true
-spring.mypages.default-page=1
-spring.mypages.default-size=10
-spring.mypages.max-page=10000
-spring.mypages.max-size=10000
-```
-
-Yaml
-
-```yaml
-spring:
- mypages:
- enabled: true
- sql-dialect: MYSQL
- count-expr: '*'
- page-field: page
- size-field: size
- offset-field: offset
- rows-field: rows
- count-expr-field: countExpr
- count-method-name-field: countMethodName
- enable-count-field: enableCount
- skip-query-if-count-equals-zero: true
- use-generated-if-count-method-is-missing: true
- default-page: 1
- default-size: 10
- max-page: 10000
- max-size: 10000
-```
\ No newline at end of file
diff --git a/docs/USERGUIDE.ZH_CN.md b/docs/USERGUIDE.ZH_CN.md
deleted file mode 100644
index 90942c1..0000000
--- a/docs/USERGUIDE.ZH_CN.md
+++ /dev/null
@@ -1,730 +0,0 @@
-# 1. 简介
-
-MyPages是Java实现基于[MyBatis](https://github.com/mybatis/mybatis-3)的开源分页插件,最大程度简化数据库分页查询操作,支持市面上大部分数据库,如:MySQL、PostgreSQL、Oracle、SQLServer等。
-
-# 2. 准备工作
-
-请确保您的Java版本在1.8及以上。
-
-# 3. 依赖
-
-## 3.1 Maven
-
-```xml
-
- io.leego
- mypages
- 1.1.2
-
-```
-
-## 3.2 Gradle
-
-```xml
-implementation 'io.leego:mypages:1.1.2'
-```
-
-# 4. 快速设置
-
-请注意sql-dialect必须被配置。
-
-## 4.1 MyBatis SqlSessionFactoryBean
-
-```java
-PaginationSettings settings = new PaginationSettings(SqlDialect.MYSQL);
-PaginationInterceptor paginationInterceptor = new PaginationInterceptor(settings);
-Interceptor[] plugins = new Interceptor[]{paginationInterceptor};
-SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
-sqlSessionFactoryBean.setPlugins(plugins);
-```
-
-## 4.2 Spring
-
-要在Spring中使用MyBatis,至少需要在Spring应用程序上下文中定义两个东西:SqlSessionFactory对象和至少一个mapper接口。
-
-在MyBatis-Spring中,SqlSessionFactoryBean用于创建SqlSessionFactory。要配置工厂bean,请在Spring配置文件中放入以下内容:
-
-## 4.3 Spring XML
-
-```xml
-
-
-
-
-
-
-```
-
-## 4.4 Spring Boot
-
-```java
-@Configuration
-public class MybatisConfiguration {
- @Bean
- public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
- Interceptor[] plugins = new Interceptor[]{paginationInterceptor()};
- SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
- sqlSessionFactoryBean.setDataSource(dataSource);
- sqlSessionFactoryBean.setPlugins(plugins);
- return sqlSessionFactoryBean.getObject();
- }
-
- @Bean
- public PaginationInterceptor paginationInterceptor() {
- PaginationSettings settings = new PaginationSettings(SqlDialect.MYSQL);
- return new PaginationInterceptor(settings);
- }
-}
-```
-
-## 4.5 Spring Boot Starter
-
-> * 请使用: [mypages-spring-boot-starter](STARTER_USERGUIDE.ZH_CN.md)
-
-# 5. 快速开始
-
-假设存在如下定义的类:
-
-```java
-import io.leego.mypages.annotation.Pagination;
-import io.leego.mypages.annotation.Page;
-import io.leego.mypages.annotation.Size;
-
-@Pagination
-public class Pageable {
- @Page
- private Integer page;
- @Size
- private Integer size;
-
- public Pageable(Integer page, Integer size) {
- this.page = page;
- this.size = size;
- }
- /* getter setter */
-}
-```
-
-假设存在如下定义的Mapper:
-
-```java
-public interface FooMapper {
- @Select("SELECT * FROM foo")
- List query(Pageable pageable);
-}
-```
-
-调用查询方法:
-
-```java
-import io.leego.mypages.util.Page;
-
-@Service
-public class QueryTests {
- @Autowired
- private FooMapper fooMapper;
-
- public Page query() {
- return Page.of(fooMapper.query(new Pageable(1, 10)));
- }
-}
-```
-
-# 6. 启用分页
-
-## 6.1 注解 (推荐)
-
-使用 `@Pagination`、`@Page`、`@Size`、`@Offset`、`@Rows` 注解.
-
-```java
-@Pagination
-public class Pageable {
- @Page
- private Integer page;
- @Size
- private Integer size;
- @Offset
- private Integer offset;
- @Rows
- private Integer rows;
- /* getter setter */
-}
-```
-
-更多注解: `@CountExpr`、`@CountMethodName`、`@DisableCount`、`@DisablePagination`.
-
-## 6.2 PaginationInterceptor配置 (推荐)
-
-配置拦截器:
-
-```java
-PaginationSettings settings = PaginationSettings.builder()
- .sqlDialect(SqlDialect.MYSQL)
- .pageField("page")
- .sizeField("size")
- .build();
-PaginationInterceptor interceptor = new PaginationInterceptor(settings);
-```
-
-### 6.2.1 定义一个分页类
-
-假设存在一个带分页参数的类:
-
-```java
-public class Pageable {
- private Integer page;
- private Integer size;
-
- public Pageable(Integer page, Integer size) {
- this.page = page;
- this.size = size;
- }
- /* getter setter */
-}
-```
-
-假设存在如下定义的Mapper:
-
-```java
-public interface FooMapper {
- @Select("SELECT * FROM foo")
- List query(Pageable pageable);
-}
-```
-
-调用查询方法:
-
-```java
-import io.leego.mypages.util.Page;
-
-@Service
-public class QueryTests {
- @Autowired
- private FooMapper fooMapper;
-
- public Page query() {
- return Page.of(fooMapper.query(new Pageable(1, 10)));
- }
-}
-```
-
-### 6.2.2 MyBatis `@Param`
-
-假设存在如下定义的Mapper:
-
-```java
-public interface FooMapper {
- @Select("SELECT * FROM foo")
- List query(@Param("page") Integer page, @Param("size") Integer size);
-}
-```
-
-调用查询方法:
-
-```java
-import io.leego.mypages.util.Page;
-
-@Service
-public class QueryTests {
- @Autowired
- private FooMapper fooMapper;
-
- public Page query() {
- return Page.of(fooMapper.query(1, 10));
- }
-}
-```
-
-### 6.2.3 Map
-
-假设存在如下定义的Mapper:
-
-```java
-public interface FooMapper {
- @Select("SELECT * FROM foo")
- List query(Map map);
-}
-```
-
-调用查询方法:
-
-```java
-import io.leego.mypages.util.Page;
-
-@Service
-public class QueryTests {
- @Autowired
- private FooMapper fooMapper;
-
- public Page query() {
- Map map = new HashMap<>();
- map.put("size", 1);
- map.put("page", 10);
- return Page.of(fooMapper.query(map));
- }
-}
-```
-
-### 更多配置
-
-```java
-PaginationSettings settings = PaginationSettings.builder()
- .sqlDialect(SqlDialect.MYSQL) // 指定SqlDialect。
- .countExpr("*") // 设置count字段名称,默认值为"*"。
- .pageField("page") // 从参数字段中获取page值。
- .sizeField("size") // 从参数字段中获取size值。
- .offsetField("offset") // 从参数字段中获取offset值。
- .rowsField("rows") // 从参数字段中获取rows值。
- .countExprField("countExpr") // 从参数字段中获取count表达式。
- .countMethodNameField("countMethodName") // 从参数字段中获取自定义count方法名称。
- .enableCountField("enableCount") // 从参数字段中判断是否启用count。
- .skipQueryIfCountEqualsZero(true) // 是否跳过查询如果总数量为0。
- .useGeneratedIfCountMethodIsMissing(true) // 是否使用自动生成的count方法如果指定count方法不存在。
- .defaultPage(1) // 如果page为空或小于1,则用default-page替换page。
- .defaultSize(10) // 如果size为空或小于1,则用default-size替换size。
- .maxPage(10000) // 如果page大于max-page,则用max-page替换page。
- .maxSize(10000) // 如果size大于max-size,则用max-size替换size。
- .build();
-PaginationInterceptor interceptor = new PaginationInterceptor(settings);
-```
-
-## 6.3 实现 `io.leego.mypages.util.Pageable`
-
-定义一个实现 `io.leego.mypages.util.Pageable`接口的类.
-
-```java
-public class PageRequest implements io.leego.mypages.util.Pageable {
- private Integer page;
- private Integer size;
- private Integer offset;
- private Integer rows;
-
- @Override
- public Integer getPage() {
- return page;
- }
-
- public void setPage(Integer page) {
- this.page = page;
- }
-
- @Override
- public Integer getSize() {
- return size;
- }
-
- public void setSize(Integer size) {
- this.size = size;
- }
-
- @Override
- public Integer getOffset() {
- return offset;
- }
-
- public void setOffset(Integer offset) {
- this.offset = offset;
- }
-
- @Override
- public Integer getRows() {
- return rows;
- }
-
- public void setRows(Integer rows) {
- this.rows = rows;
- }
-}
-```
-
-# 7. 使用自定义Count方法
-
-## 7.1 注解
-
-```java
-@Pagination
-public class Pageable {
- @Page
- private Integer page;
- @Size
- private Integer size;
- @CountMethodName
- private String countMethodName;
-
- public Pageable(Integer page, Integer size, String countMethodName) {
- this.page = page;
- this.size = size;
- this.countMethodName = countMethodName;
- }
- /* getter setter */
-}
-```
-
-## 7.2 PaginationInterceptor配置
-
-```java
-public class Pageable {
- private Integer page;
- private Integer size;
- private String countMethodName;
-
- public Pageable(Integer page, Integer size, String countMethodName) {
- this.page = page;
- this.size = size;
- this.countMethodName = countMethodName;
- }
- /* getter setter */
-}
-```
-
-```java
-PaginationSettings settings = PaginationSettings.builder()
- .sqlDialect(SqlDialect.MYSQL)
- .pageField("page")
- .sizeField("size")
- .countMethodNameField("countMethodName")
- .build();
-PaginationInterceptor interceptor = new PaginationInterceptor(settings);
-```
-
-## 7.3 调用Query和Count方法
-
-假设存在如下定义的Mapper:
-
-```java
-public interface FooMapper {
- @Select("SELECT * FROM foo")
- List query(Pageable pageable);
-
- @Select("SELECT COUNT(*) FROM foo")
- long count(Pageable pageable);
-}
-```
-
-指定Count方法名称:
-
-```java
-import io.leego.mypages.util.Page;
-
-@Service
-public class QueryTests {
- @Autowired
- private FooMapper fooMapper;
-
- public Page query() {
- // Specifies the count method name.
- return Page.of(fooMapper.query(new Pageable(1, 10, "count")));
- }
-}
-```
-
-# 8. 参数合理化
-
-如果分页参数无效,需要合理化参数,可以设置以下参数:
-
-**defaultPage**: 如果page为空或小于1,则用default-page替换page。
-**defaultSize**: 如果size为空或小于1,则用default-size替换size。
-**maxPage**: 如果page大于max-page,则用max-page替换page。
-**maxSize**: 如果size大于max-size,则用max-size替换size。
-
-## 8.1 注解配置
-
-```java
-@Pagination(defaultPage = 1, defaultSize = 10, maxPage = 10000, maxSize = 10000)
-public class Pageable {
-}
-```
-
-## 8.2 PaginationInterceptor配置
-
-```java
-PaginationSettings settings = PaginationSettings.builder()
- .sqlDialect(SqlDialect.MYSQL)
- .defaultPage(1)
- .defaultSize(10)
- .maxPage(10000)
- .maxSize(10000)
- .build();
-PaginationInterceptor interceptor = new PaginationInterceptor(settings);
-```
-
-# 9. 查询结果
-
-如果调用执行成功结束,它将返回一个`PaginationCollection`实例。
-
-## 9.1 使用 `io.leego.mypages.util.Page`
-
-#### 9.1.1 包装
-
-```java
-Page result = Page.of(fooMapper.query(pageable));
-```
-
-#### 9.1.2 转化
-
-```java
-Page result=Page.of(fooMapper.query(pageable),foo->new Bar(foo));
-```
-
-#### 9.1.3 映射
-
-```java
-Page result=Page.of(fooMapper.query(pageable)).map(foo->new Bar(foo));
-```
-
-## 9.2 自定义包装类和工具类
-
-#### 9.2.1 包装类
-
-定义一个带分页结果的类:
-
-```java
-public class Pagination implements Serializable {
- private static final long serialVersionUID = 3214571808482585491L;
- /** Data list. */
- protected List list;
- /** One-based page index. */
- protected Integer page;
- /** The size of the page to be returned. */
- protected Integer size;
- /** The quantity of data. */
- protected Long total;
- /** The quantity of data pages. */
- protected Long pages;
- /** Returns {@code true} if there is a next page. */
- protected Boolean next;
- /** Returns {@code true} if there is a previous page. */
- protected Boolean previous;
-
- public Pagination() {
- }
-
- public Pagination(List list) {
- this.list = list;
- }
-
- public Pagination(List list, Long total) {
- this.list = list;
- this.total = total;
- }
-
- public Pagination(List list, Integer page, Integer size) {
- this.list = list;
- this.page = page;
- this.size = size;
- }
-
- public Pagination(List list, Integer page, Integer size, Long total, Long pages, Boolean next, Boolean previous) {
- this.list = list;
- this.page = page;
- this.size = size;
- this.total = total;
- this.pages = pages;
- this.next = next;
- this.previous = previous;
- }
-
- public static Pagination of(List list, Integer page, Integer size, Long total, Long pages, Boolean next, Boolean previous) {
- return new Pagination<>(list, page, size, total, pages, next, previous);
- }
-
- public static Pagination of(List list, Integer page, Integer size, Long total) {
- if (page == null || size == null) {
- return new Pagination<>(list, total);
- }
- if (total == null) {
- return new Pagination<>(list, page, size);
- }
- boolean next;
- boolean previous;
- long pages;
- if (page > 0 && size > 0) {
- next = page.longValue() * size < total;
- previous = page != 1;
- pages = total % size > 0 ? total / size + 1 : total / size;
- } else {
- next = false;
- previous = false;
- pages = 0L;
- }
- return new Pagination<>(list, page, size, total, pages, next, previous);
- }
-
- public static Pagination of(List list, Integer page, Integer size) {
- return new Pagination<>(list, page, size);
- }
-
- public static Pagination of(List list, Long total) {
- return new Pagination<>(list, total);
- }
-
- public static Pagination of(List list) {
- return new Pagination<>(list);
- }
-
- public static Pagination of(Collection collection) {
- if (collection == null) {
- return new Pagination<>(new ArrayList<>());
- }
- if (collection instanceof List) {
- return new Pagination<>((List) collection);
- }
- return new Pagination<>(new ArrayList<>(collection));
- }
-
- public static Pagination empty() {
- return new Pagination<>(new ArrayList<>());
- }
-
- public Pagination map(Function super T, ? extends U> converter) {
- return new Pagination<>(list == null ? null : list.stream().map(converter).collect(Collectors.toList()),
- page, size, total, pages, next, previous);
- }
-
- public List getList() {
- return list;
- }
-
- public void setList(List list) {
- this.list = list;
- }
-
- public Integer getPage() {
- return page;
- }
-
- public void setPage(Integer page) {
- this.page = page;
- }
-
- public Integer getSize() {
- return size;
- }
-
- public void setSize(Integer size) {
- this.size = size;
- }
-
- public Long getTotal() {
- return total;
- }
-
- public void setTotal(Long total) {
- this.total = total;
- }
-
- public Long getPages() {
- return pages;
- }
-
- public void setPages(Long pages) {
- this.pages = pages;
- }
-
- public Boolean getNext() {
- return next;
- }
-
- public void setNext(Boolean next) {
- this.next = next;
- }
-
- public Boolean getPrevious() {
- return previous;
- }
-
- public void setPrevious(Boolean previous) {
- this.previous = previous;
- }
-}
-```
-
-#### 9.2.2 分页工具类
-
-定义一个分页工具类
-
-```java
-public final class PaginationUtils {
- private PaginationUtils() {
- }
-
- public static Pagination of(List source) {
- if (source == null) {
- return Pagination.empty();
- }
- if (!(source instanceof PaginationList)) {
- return Pagination.of(source);
- }
- PaginationList s = (PaginationList) source;
- return Pagination.of(source, s.getPage(), s.getSize(), s.getTotal());
- }
-
- public static Pagination of(Collection source) {
- if (source == null) {
- return Pagination.empty();
- }
- if (!(source instanceof PaginationCollection)) {
- return Pagination.of(source);
- }
- PaginationCollection s = (PaginationCollection) source;
- return Pagination.of(toList(source), s.getPage(), s.getSize(), s.getTotal());
- }
-
- public static Pagination of(Collection source, Function super S, ? extends T> mapper) {
- if (source == null) {
- return Pagination.empty();
- }
- if (!(source instanceof PaginationCollection)) {
- return Pagination.of(mapping(source, mapper));
- }
- PaginationCollection s = (PaginationCollection) source;
- return Pagination.of(mapping(source, mapper), s.getPage(), s.getSize(), s.getTotal());
- }
-
- public static Pagination transfer(Collection source, Collection target) {
- if (source == null || target == null) {
- return Pagination.empty();
- }
- if (!(source instanceof PaginationCollection)) {
- return Pagination.of(toList(target));
- }
- PaginationCollection s = (PaginationCollection) source;
- return Pagination.of(toList(target), s.getPage(), s.getSize(), s.getTotal());
- }
-
- private static List mapping(Collection source, Function super S, ? extends T> mapper) {
- Objects.requireNonNull(mapper);
- if (source == null || source.isEmpty()) {
- return new ArrayList<>();
- }
- return source.stream().map(mapper).collect(Collectors.toList());
- }
-
- private static List toList(Collection collection) {
- if (collection == null) {
- return new ArrayList<>();
- }
- if (collection instanceof List) {
- return (List) collection;
- }
- return new ArrayList<>(collection);
- }
-
-}
-```
-
-使用自定义工具类:
-
-```java
-Pagination result=PaginationUtils.of(fooMapper.query(pageable));
-```
-
-```java
-Pagination result=PaginationUtils.of(fooMapper.query(pageable),foo->new Bar(foo));
-```
diff --git a/docs/USERGUIDE.md b/docs/USERGUIDE.md
deleted file mode 100644
index 9c3c6b3..0000000
--- a/docs/USERGUIDE.md
+++ /dev/null
@@ -1,730 +0,0 @@
-# 1. Introduction
-
-MyPages is a java based, open source pagination plugin for [MyBatis](https://github.com/mybatis/mybatis-3) that simplifies database paging queries.
-
-# 2. Getting Started
-
-Please make sure the Java version is 1.8 and above.
-
-# 3. Dependency
-
-## 3.1 Maven
-
-```xml
-
- io.leego
- mypages
- 1.1.2
-
-```
-
-## 3.2 Gradle
-
-```xml
-implementation 'io.leego:mypages:1.1.2'
-```
-
-# 4. Quick Setup
-
-Please notice that the PaginationInterceptor requires SqlDialect.
-
-## 4.1 MyBatis SqlSessionFactoryBean
-
-```java
-PaginationSettings settings = new PaginationSettings(SqlDialect.MYSQL);
-PaginationInterceptor paginationInterceptor = new PaginationInterceptor(settings);
-Interceptor[] plugins = new Interceptor[]{paginationInterceptor};
-SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
-sqlSessionFactoryBean.setPlugins(plugins);
-```
-
-## 4.2 Spring
-
-To use MyBatis with Spring you need at least two things defined in the Spring application context: an SqlSessionFactory and at least one mapper interface.
-
-In MyBatis-Spring, an SqlSessionFactoryBean is used to create an SqlSessionFactory. To configure the factory bean, put the following in the Spring configuration file:
-
-## 4.3 Spring XML
-
-```xml
-
-
-
-
-
-
-```
-
-## 4.4 Spring Boot
-
-```java
-@Configuration
-public class MybatisConfiguration {
- @Bean
- public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
- Interceptor[] plugins = new Interceptor[]{paginationInterceptor()};
- SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
- sqlSessionFactoryBean.setDataSource(dataSource);
- sqlSessionFactoryBean.setPlugins(plugins);
- return sqlSessionFactoryBean.getObject();
- }
-
- @Bean
- public PaginationInterceptor paginationInterceptor() {
- PaginationSettings settings = new PaginationSettings(SqlDialect.MYSQL);
- return new PaginationInterceptor(settings);
- }
-}
-```
-
-## 4.5 Spring Boot Starter
-
-> * Please see: [mypages-spring-boot-starter](STARTER_USERGUIDE.md)
-
-# 5. Quick Start
-
-Assume there is a class defined like the following:
-
-```java
-import io.leego.mypages.annotation.Pagination;
-import io.leego.mypages.annotation.Page;
-import io.leego.mypages.annotation.Size;
-
-@Pagination
-public class Pageable {
- @Page
- private Integer page;
- @Size
- private Integer size;
-
- public Pageable(Integer page, Integer size) {
- this.page = page;
- this.size = size;
- }
- /* getter setter */
-}
-```
-
-Assume there is a mapper interface defined like the following:
-
-```java
-public interface FooMapper {
- @Select("SELECT * FROM foo")
- List query(Pageable pageable);
-}
-```
-
-Call query method:
-
-```java
-import io.leego.mypages.util.Page;
-
-@Service
-public class QueryTests {
- @Autowired
- private FooMapper fooMapper;
-
- public Page query() {
- return Page.of(fooMapper.query(new Pageable(1, 10)));
- }
-}
-```
-
-# 6. Enable Pagination
-
-## 6.1 Annotations (Recommended)
-
-Using `@Pagination`, `@Page`, `@Size`, `@Offset`, `@Rows` annotations.
-
-```java
-@Pagination
-public class Pageable {
- @Page
- private Integer page;
- @Size
- private Integer size;
- @Offset
- private Integer offset;
- @Rows
- private Integer rows;
- /* getter setter */
-}
-```
-
-More annotations: `@CountExpr`, `@CountMethodName`, `@DisableCount`, `@DisablePagination`.
-
-## 6.2 PaginationInterceptor Configuration (Recommended)
-
-Configure the interceptor.
-
-```java
-PaginationSettings settings = PaginationSettings.builder()
- .sqlDialect(SqlDialect.MYSQL)
- .pageField("page")
- .sizeField("size")
- .build();
-PaginationInterceptor interceptor = new PaginationInterceptor(settings);
-```
-
-### 6.2.1 Define a class
-
-Define a class with paging parameters.
-
-```java
-public class Pageable {
- private Integer page;
- private Integer size;
-
- public Pageable(Integer page, Integer size) {
- this.page = page;
- this.size = size;
- }
- /* getter setter */
-}
-```
-
-Assume there is a mapper interface defined like the following:
-
-```java
-public interface FooMapper {
- @Select("SELECT * FROM foo")
- List query(Pageable pageable);
-}
-```
-
-Call query method:
-
-```java
-import io.leego.mypages.util.Page;
-
-@Service
-public class QueryTests {
- @Autowired
- private FooMapper fooMapper;
-
- public Page query() {
- return Page.of(fooMapper.query(new Pageable(1, 10)));
- }
-}
-```
-
-### 6.2.2 MyBatis `@Param`
-
-Assume there is a mapper interface defined like the following:
-
-```java
-public interface FooMapper {
- @Select("SELECT * FROM foo")
- List query(@Param("page") Integer page, @Param("size") Integer size);
-}
-```
-
-Call query method:
-
-```java
-import io.leego.mypages.util.Page;
-
-@Service
-public class QueryTests {
- @Autowired
- private FooMapper fooMapper;
-
- public Page query() {
- return Page.of(fooMapper.query(1, 10));
- }
-}
-```
-
-### 6.2.3 Map
-
-Assume there is a mapper interface defined like the following:
-
-```java
-public interface FooMapper {
- @Select("SELECT * FROM foo")
- List query(Map map);
-}
-```
-
-Call query method:
-
-```java
-import io.leego.mypages.util.Page;
-
-@Service
-public class QueryTests {
- @Autowired
- private FooMapper fooMapper;
-
- public Page query() {
- Map map = new HashMap<>();
- map.put("size", 1);
- map.put("page", 10);
- return Page.of(fooMapper.query(map));
- }
-}
-```
-
-### More configurations.
-
-```java
-PaginationSettings settings = PaginationSettings.builder()
- .sqlDialect(SqlDialect.MYSQL) // Specifies sql-dialect.
- .countExpr("*") // The column name or expression, the default value is "*"
.
- .pageField("page") // Obtains the page value from parameter.
- .sizeField("size") // Obtains the size value from parameter.
- .offsetField("offset") // Obtains the offset value from parameter.
- .rowsField("rows") // Obtains the rows value from parameter.
- .countExprField("countExpr") // Obtains the count expression from parameter.
- .countMethodNameField("countMethodName") // Obtains the count-method-name from parameter.
- .enableCountField("enableCount") // Obtains the enable-count from parameter.
- .skipQueryIfCountEqualsZero(true) // Whether to skip query if total quantity equals zero.
- .useGeneratedIfCountMethodIsMissing(true) // Whether to use generated if the specified count method is missing.
- .defaultPage(1) // Replaces the page with default-page if the page is null or less than 1.
- .defaultSize(10) // Replaces the size with default-size if the size is null or less than 1.
- .maxPage(10000) // Replaces the page with max-page if the page is greater than max-page.
- .maxSize(10000) // Replaces the size with max-size if the size is greater than max-size.
- .build();
-PaginationInterceptor interceptor = new PaginationInterceptor(settings);
-```
-
-## 6.3 Implements `io.leego.mypages.util.Pageable`
-
-Define a class implements `io.leego.mypages.util.Pageable`.
-
-```java
-public class PageRequest implements io.leego.mypages.util.Pageable {
- private Integer page;
- private Integer size;
- private Integer offset;
- private Integer rows;
-
- @Override
- public Integer getPage() {
- return page;
- }
-
- public void setPage(Integer page) {
- this.page = page;
- }
-
- @Override
- public Integer getSize() {
- return size;
- }
-
- public void setSize(Integer size) {
- this.size = size;
- }
-
- @Override
- public Integer getOffset() {
- return offset;
- }
-
- public void setOffset(Integer offset) {
- this.offset = offset;
- }
-
- @Override
- public Integer getRows() {
- return rows;
- }
-
- public void setRows(Integer rows) {
- this.rows = rows;
- }
-}
-```
-
-# 7. Using custom count methods
-
-## 7.1 Annotations
-
-```java
-@Pagination
-public class Pageable {
- @Page
- private Integer page;
- @Size
- private Integer size;
- @CountMethodName
- private String countMethodName;
-
- public Pageable(Integer page, Integer size, String countMethodName) {
- this.page = page;
- this.size = size;
- this.countMethodName = countMethodName;
- }
- /* getter setter */
-}
-```
-
-## 7.2 PaginationInterceptor Configuration
-
-```java
-public class Pageable {
- private Integer page;
- private Integer size;
- private String countMethodName;
-
- public Pageable(Integer page, Integer size, String countMethodName) {
- this.page = page;
- this.size = size;
- this.countMethodName = countMethodName;
- }
- /* getter setter */
-}
-```
-
-```java
-PaginationSettings settings = PaginationSettings.builder()
- .sqlDialect(SqlDialect.MYSQL)
- .pageField("page")
- .sizeField("size")
- .countMethodNameField("countMethodName")
- .build();
-PaginationInterceptor interceptor = new PaginationInterceptor(settings);
-```
-
-## 7.3 Call methods:
-
-Assume there is a mapper interface defined like the following:
-
-```java
-public interface FooMapper {
- @Select("SELECT * FROM foo")
- List query(Pageable pageable);
-
- @Select("SELECT COUNT(*) FROM foo")
- long count(Pageable pageable);
-}
-```
-
-Specify the count method name:
-
-```java
-import io.leego.mypages.util.Page;
-
-@Service
-public class QueryTests {
- @Autowired
- private FooMapper fooMapper;
-
- public Page query() {
- // Specifies the count method name.
- return Page.of(fooMapper.query(new Pageable(1, 10, "count")));
- }
-}
-```
-
-# 8. Parameters rationalization
-
-Rationalize the parameters if the values are invalid, the following parameters can be set:
-
-**defaultPage**: Replaces the page with default-page if the page is null or less than 1.
-**defaultSize**: Replaces the size with default-size if the size is null or less than 1.
-**maxPage**: Replaces the page with max-page if the page is greater than max-page.
-**maxSize**: Replaces the size with max-size if the size is greater than max-size.
-
-## 8.1 Annotations
-
-```java
-@Pagination(defaultPage = 1, defaultSize = 10, maxPage = 10000, maxSize = 10000)
-public class Pageable {
-}
-```
-
-## 8.2 PaginationInterceptor Configuration
-
-```java
-PaginationSettings settings = PaginationSettings.builder()
- .sqlDialect(SqlDialect.MYSQL)
- .defaultPage(1)
- .defaultSize(10)
- .maxPage(10000)
- .maxSize(10000)
- .build();
-PaginationInterceptor interceptor = new PaginationInterceptor(settings);
-```
-
-# 9. Query Results
-
-If the invocation proceed, it will return an instance of the `PaginationCollection`.
-
-## 9.1 Using `io.leego.mypages.util.Page`
-
-#### 9.1.1 Wrap
-
-```java
-Page result = Page.of(fooMapper.query(pageable));
-```
-
-#### 9.1.2 Convert
-
-```java
-Page result=Page.of(fooMapper.query(pageable),foo->new Bar(foo));
-```
-
-#### 9.1.3 Mapping
-
-```java
-Page result=Page.of(fooMapper.query(pageable)).map(foo->new Bar(foo));
-```
-
-## 9.2 Using Custom Pagination Class
-
-For example:
-
-#### 9.2.1 Custom Pagination Class
-
-Assume there is a class defined like the following:
-
-```java
-public class Pagination implements Serializable {
- private static final long serialVersionUID = 3214571808482585491L;
- /** Data list. */
- protected List list;
- /** One-based page index. */
- protected Integer page;
- /** The size of the page to be returned. */
- protected Integer size;
- /** The quantity of data. */
- protected Long total;
- /** The quantity of data pages. */
- protected Long pages;
- /** Returns {@code true} if there is a next page. */
- protected Boolean next;
- /** Returns {@code true} if there is a previous page. */
- protected Boolean previous;
-
- public Pagination() {
- }
-
- public Pagination(List list) {
- this.list = list;
- }
-
- public Pagination(List list, Long total) {
- this.list = list;
- this.total = total;
- }
-
- public Pagination(List list, Integer page, Integer size) {
- this.list = list;
- this.page = page;
- this.size = size;
- }
-
- public Pagination(List list, Integer page, Integer size, Long total, Long pages, Boolean next, Boolean previous) {
- this.list = list;
- this.page = page;
- this.size = size;
- this.total = total;
- this.pages = pages;
- this.next = next;
- this.previous = previous;
- }
-
- public static Pagination of(List list, Integer page, Integer size, Long total, Long pages, Boolean next, Boolean previous) {
- return new Pagination<>(list, page, size, total, pages, next, previous);
- }
-
- public static Pagination of(List list, Integer page, Integer size, Long total) {
- if (page == null || size == null) {
- return new Pagination<>(list, total);
- }
- if (total == null) {
- return new Pagination<>(list, page, size);
- }
- boolean next;
- boolean previous;
- long pages;
- if (page > 0 && size > 0) {
- next = page.longValue() * size < total;
- previous = page != 1;
- pages = total % size > 0 ? total / size + 1 : total / size;
- } else {
- next = false;
- previous = false;
- pages = 0L;
- }
- return new Pagination<>(list, page, size, total, pages, next, previous);
- }
-
- public static Pagination of(List list, Integer page, Integer size) {
- return new Pagination<>(list, page, size);
- }
-
- public static Pagination of(List list, Long total) {
- return new Pagination<>(list, total);
- }
-
- public static Pagination of(List list) {
- return new Pagination<>(list);
- }
-
- public static Pagination of(Collection collection) {
- if (collection == null) {
- return new Pagination<>(new ArrayList<>());
- }
- if (collection instanceof List) {
- return new Pagination<>((List) collection);
- }
- return new Pagination<>(new ArrayList<>(collection));
- }
-
- public static Pagination empty() {
- return new Pagination<>(new ArrayList<>());
- }
-
- public Pagination map(Function super T, ? extends U> converter) {
- return new Pagination<>(list == null ? null : list.stream().map(converter).collect(Collectors.toList()),
- page, size, total, pages, next, previous);
- }
-
- public List getList() {
- return list;
- }
-
- public void setList(List list) {
- this.list = list;
- }
-
- public Integer getPage() {
- return page;
- }
-
- public void setPage(Integer page) {
- this.page = page;
- }
-
- public Integer getSize() {
- return size;
- }
-
- public void setSize(Integer size) {
- this.size = size;
- }
-
- public Long getTotal() {
- return total;
- }
-
- public void setTotal(Long total) {
- this.total = total;
- }
-
- public Long getPages() {
- return pages;
- }
-
- public void setPages(Long pages) {
- this.pages = pages;
- }
-
- public Boolean getNext() {
- return next;
- }
-
- public void setNext(Boolean next) {
- this.next = next;
- }
-
- public Boolean getPrevious() {
- return previous;
- }
-
- public void setPrevious(Boolean previous) {
- this.previous = previous;
- }
-}
-```
-
-#### 9.2.2 Pagination Utils
-
-For example:
-
-```java
-public final class PaginationUtils {
- private PaginationUtils() {
- }
-
- public static Pagination of(List source) {
- if (source == null) {
- return Pagination.empty();
- }
- if (!(source instanceof PaginationList)) {
- return Pagination.of(source);
- }
- PaginationList s = (PaginationList) source;
- return Pagination.of(source, s.getPage(), s.getSize(), s.getTotal());
- }
-
- public static Pagination of(Collection source) {
- if (source == null) {
- return Pagination.empty();
- }
- if (!(source instanceof PaginationCollection)) {
- return Pagination.of(source);
- }
- PaginationCollection s = (PaginationCollection) source;
- return Pagination.of(toList(source), s.getPage(), s.getSize(), s.getTotal());
- }
-
- public static Pagination of(Collection source, Function super S, ? extends T> mapper) {
- if (source == null) {
- return Pagination.empty();
- }
- if (!(source instanceof PaginationCollection)) {
- return Pagination.of(mapping(source, mapper));
- }
- PaginationCollection s = (PaginationCollection) source;
- return Pagination.of(mapping(source, mapper), s.getPage(), s.getSize(), s.getTotal());
- }
-
- public static Pagination transfer(Collection source, Collection target) {
- if (source == null || target == null) {
- return Pagination.empty();
- }
- if (!(source instanceof PaginationCollection)) {
- return Pagination.of(toList(target));
- }
- PaginationCollection s = (PaginationCollection) source;
- return Pagination.of(toList(target), s.getPage(), s.getSize(), s.getTotal());
- }
-
- private static List mapping(Collection source, Function super S, ? extends T> mapper) {
- Objects.requireNonNull(mapper);
- if (source == null || source.isEmpty()) {
- return new ArrayList<>();
- }
- return source.stream().map(mapper).collect(Collectors.toList());
- }
-
- private static List toList(Collection collection) {
- if (collection == null) {
- return new ArrayList<>();
- }
- if (collection instanceof List) {
- return (List) collection;
- }
- return new ArrayList<>(collection);
- }
-
-}
-```
-
-```java
-Pagination result=PaginationUtils.of(fooMapper.query(pageable));
-```
-
-```java
-Pagination result=PaginationUtils.of(fooMapper.query(pageable),foo->new Bar(foo));
-```
diff --git a/mypages-samples/mypages-sample-java/pom.xml b/mypages-samples/mypages-sample-java/pom.xml
new file mode 100644
index 0000000..329c732
--- /dev/null
+++ b/mypages-samples/mypages-sample-java/pom.xml
@@ -0,0 +1,37 @@
+
+
+ 4.0.0
+
+
+ io.leego
+ mypages-samples
+ 2.0.0
+
+
+ mypages-sample-java
+ ${project.artifactId}
+
+
+
+ io.leego
+ mypages
+
+
+ org.mybatis
+ mybatis
+
+
+ com.zaxxer
+ HikariCP
+
+
+ mysql
+ mysql-connector-java
+
+
+
+
\ No newline at end of file
diff --git a/mypages-samples/mypages-sample-java/src/main/java/io/leego/mypages/sample/MyPagesApplication.java b/mypages-samples/mypages-sample-java/src/main/java/io/leego/mypages/sample/MyPagesApplication.java
new file mode 100644
index 0000000..b3c2aa6
--- /dev/null
+++ b/mypages-samples/mypages-sample-java/src/main/java/io/leego/mypages/sample/MyPagesApplication.java
@@ -0,0 +1,72 @@
+package io.leego.mypages.sample;
+
+import com.zaxxer.hikari.HikariConfig;
+import com.zaxxer.hikari.HikariDataSource;
+import io.leego.mypages.dialect.Database;
+import io.leego.mypages.interceptor.PaginationInterceptor;
+import io.leego.mypages.interceptor.PaginationSettings;
+import io.leego.mypages.sample.entity.User;
+import io.leego.mypages.sample.mapper.UserMapper;
+import io.leego.mypages.util.Page;
+import org.apache.ibatis.mapping.Environment;
+import org.apache.ibatis.session.Configuration;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.session.SqlSessionFactoryBuilder;
+import org.apache.ibatis.transaction.TransactionFactory;
+import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.sql.DataSource;
+import java.util.List;
+
+/**
+ * @author Yihleego
+ */
+public class MyPagesApplication {
+ private static final Logger logger = LoggerFactory.getLogger(MyPagesApplication.class);
+
+ public static void main(String[] args) {
+ new MyPagesApplication().run();
+ }
+
+ public void run() {
+ DataSource dataSource = dataSource();
+ SqlSessionFactory sqlSessionFactory = sqlSessionFactory(dataSource);
+ try (SqlSession session = sqlSessionFactory.openSession(false)) {
+ UserMapper userMapper = session.getMapper(UserMapper.class);
+ List list = userMapper.query(1, 10);
+ Page page = Page.of(list);
+ logger.info("{}", page);
+ }
+ }
+
+ public DataSource dataSource() {
+ HikariConfig config = new HikariConfig();
+ config.setDriverClassName("com.mysql.cj.jdbc.Driver");
+ config.setJdbcUrl("jdbc:mysql://localhost:3306/mypages?serverTimezone=GMT%2B8");
+ config.setUsername("root");
+ config.setPassword("123456");
+ return new HikariDataSource(config);
+ }
+
+ public SqlSessionFactory sqlSessionFactory(DataSource dataSource) {
+ TransactionFactory transactionFactory = new JdbcTransactionFactory();
+ Environment environment = new Environment(SqlSessionFactory.class.getSimpleName(), transactionFactory, dataSource);
+ Configuration configuration = new Configuration(environment);
+ configuration.setMapUnderscoreToCamelCase(true);
+ configuration.addMapper(UserMapper.class);
+ configuration.addInterceptor(paginationInterceptor(dataSource));
+ return new SqlSessionFactoryBuilder().build(configuration);
+ }
+
+ public PaginationInterceptor paginationInterceptor(DataSource dataSource) {
+ PaginationSettings settings = PaginationSettings.builder()
+ .database(Database.fromDataSource(dataSource))
+ .pageField("page")
+ .sizeField("size")
+ .build();
+ return new PaginationInterceptor(settings);
+ }
+}
diff --git a/mypages-samples/mypages-sample-java/src/main/java/io/leego/mypages/sample/entity/User.java b/mypages-samples/mypages-sample-java/src/main/java/io/leego/mypages/sample/entity/User.java
new file mode 100644
index 0000000..f7a6bb5
--- /dev/null
+++ b/mypages-samples/mypages-sample-java/src/main/java/io/leego/mypages/sample/entity/User.java
@@ -0,0 +1,72 @@
+package io.leego.mypages.sample.entity;
+
+import java.time.LocalDateTime;
+
+/**
+ * @author Yihleego
+ */
+public class User {
+ private Long id;
+ private LocalDateTime createdTime;
+ private LocalDateTime updatedTime;
+ private String username;
+ private String password;
+ private String nickname;
+ private Integer status;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public LocalDateTime getCreatedTime() {
+ return createdTime;
+ }
+
+ public void setCreatedTime(LocalDateTime createdTime) {
+ this.createdTime = createdTime;
+ }
+
+ public LocalDateTime getUpdatedTime() {
+ return updatedTime;
+ }
+
+ public void setUpdatedTime(LocalDateTime updatedTime) {
+ this.updatedTime = updatedTime;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public String getNickname() {
+ return nickname;
+ }
+
+ public void setNickname(String nickname) {
+ this.nickname = nickname;
+ }
+
+ public Integer getStatus() {
+ return status;
+ }
+
+ public void setStatus(Integer status) {
+ this.status = status;
+ }
+}
diff --git a/mypages-samples/mypages-sample-java/src/main/java/io/leego/mypages/sample/mapper/UserMapper.java b/mypages-samples/mypages-sample-java/src/main/java/io/leego/mypages/sample/mapper/UserMapper.java
new file mode 100644
index 0000000..5070f15
--- /dev/null
+++ b/mypages-samples/mypages-sample-java/src/main/java/io/leego/mypages/sample/mapper/UserMapper.java
@@ -0,0 +1,15 @@
+package io.leego.mypages.sample.mapper;
+
+import io.leego.mypages.sample.entity.User;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
+
+/**
+ * @author Yihleego
+ */
+public interface UserMapper {
+ @Select("select * from user")
+ List query(@Param("page") Integer page, @Param("size") Integer size);
+}
diff --git a/mypages-samples/mypages-sample-mybatis-plus/pom.xml b/mypages-samples/mypages-sample-mybatis-plus/pom.xml
new file mode 100644
index 0000000..ace711b
--- /dev/null
+++ b/mypages-samples/mypages-sample-mybatis-plus/pom.xml
@@ -0,0 +1,41 @@
+
+
+ 4.0.0
+
+
+ io.leego
+ mypages-samples
+ 2.0.0
+
+
+ mypages-sample-mybatis-plus
+ ${project.artifactId}
+
+
+
+ io.leego
+ mypages-spring-boot-starter
+
+
+ com.baomidou
+ mybatis-plus-boot-starter
+
+
+ org.springframework.boot
+ spring-boot-starter
+
+
+ org.springframework.boot
+ spring-boot-starter-jdbc
+
+
+ mysql
+ mysql-connector-java
+
+
+
+
\ No newline at end of file
diff --git a/mypages-samples/mypages-sample-mybatis-plus/src/main/java/io/leego/mypages/sample/MyPagesApplication.java b/mypages-samples/mypages-sample-mybatis-plus/src/main/java/io/leego/mypages/sample/MyPagesApplication.java
new file mode 100644
index 0000000..663d7f7
--- /dev/null
+++ b/mypages-samples/mypages-sample-mybatis-plus/src/main/java/io/leego/mypages/sample/MyPagesApplication.java
@@ -0,0 +1,29 @@
+package io.leego.mypages.sample;
+
+import io.leego.mypages.sample.entity.User;
+import io.leego.mypages.sample.mapper.UserMapper;
+import io.leego.mypages.util.Page;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.ApplicationContext;
+
+import java.util.List;
+
+/**
+ * @author Yihleego
+ */
+@SpringBootApplication
+public class MyPagesApplication {
+ private static final Logger logger = LoggerFactory.getLogger(MyPagesApplication.class);
+
+ public static void main(String[] args) {
+ ApplicationContext applicationContext = SpringApplication.run(MyPagesApplication.class, args);
+ UserMapper userMapper = applicationContext.getBean(UserMapper.class);
+ List list = userMapper.query(1, 10);
+ Page page = Page.of(list);
+ logger.info("{}", page);
+ }
+
+}
diff --git a/mypages-samples/mypages-sample-mybatis-plus/src/main/java/io/leego/mypages/sample/entity/User.java b/mypages-samples/mypages-sample-mybatis-plus/src/main/java/io/leego/mypages/sample/entity/User.java
new file mode 100644
index 0000000..f7a6bb5
--- /dev/null
+++ b/mypages-samples/mypages-sample-mybatis-plus/src/main/java/io/leego/mypages/sample/entity/User.java
@@ -0,0 +1,72 @@
+package io.leego.mypages.sample.entity;
+
+import java.time.LocalDateTime;
+
+/**
+ * @author Yihleego
+ */
+public class User {
+ private Long id;
+ private LocalDateTime createdTime;
+ private LocalDateTime updatedTime;
+ private String username;
+ private String password;
+ private String nickname;
+ private Integer status;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public LocalDateTime getCreatedTime() {
+ return createdTime;
+ }
+
+ public void setCreatedTime(LocalDateTime createdTime) {
+ this.createdTime = createdTime;
+ }
+
+ public LocalDateTime getUpdatedTime() {
+ return updatedTime;
+ }
+
+ public void setUpdatedTime(LocalDateTime updatedTime) {
+ this.updatedTime = updatedTime;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public String getNickname() {
+ return nickname;
+ }
+
+ public void setNickname(String nickname) {
+ this.nickname = nickname;
+ }
+
+ public Integer getStatus() {
+ return status;
+ }
+
+ public void setStatus(Integer status) {
+ this.status = status;
+ }
+}
diff --git a/mypages-samples/mypages-sample-mybatis-plus/src/main/java/io/leego/mypages/sample/mapper/UserMapper.java b/mypages-samples/mypages-sample-mybatis-plus/src/main/java/io/leego/mypages/sample/mapper/UserMapper.java
new file mode 100644
index 0000000..444ea67
--- /dev/null
+++ b/mypages-samples/mypages-sample-mybatis-plus/src/main/java/io/leego/mypages/sample/mapper/UserMapper.java
@@ -0,0 +1,18 @@
+package io.leego.mypages.sample.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import io.leego.mypages.sample.entity.User;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
+
+/**
+ * @author Yihleego
+ */
+@Mapper
+public interface UserMapper extends BaseMapper {
+ @Select("select * from user")
+ List query(@Param("page") Integer page, @Param("size") Integer size);
+}
diff --git a/mypages-samples/mypages-sample-mybatis-plus/src/main/resources/application.properties b/mypages-samples/mypages-sample-mybatis-plus/src/main/resources/application.properties
new file mode 100644
index 0000000..e11d076
--- /dev/null
+++ b/mypages-samples/mypages-sample-mybatis-plus/src/main/resources/application.properties
@@ -0,0 +1,19 @@
+# port
+server.port=10000
+# name
+spring.application.name=mypages-sample-spring-boot-starter
+# logging
+logging.level.io.leego=debug
+# datasource
+spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
+spring.datasource.url=jdbc:mysql://localhost:3306/mypages?serverTimezone=GMT%2B8
+spring.datasource.username=root
+spring.datasource.password=123456
+# mybatis
+mybatis-plus.configuration.cache-enabled=false
+mybatis-plus.configuration.local-cache-scope=STATEMENT
+mybatis-plus.configuration.jdbc-type-for-null=NULL
+mybatis-plus.configuration.map-underscore-to-camel-case=true
+# mypages
+mypages.page-field=page
+mypages.size-field=size
\ No newline at end of file
diff --git a/mypages-samples/mypages-sample-spring-boot-starter/pom.xml b/mypages-samples/mypages-sample-spring-boot-starter/pom.xml
new file mode 100644
index 0000000..d8f3f92
--- /dev/null
+++ b/mypages-samples/mypages-sample-spring-boot-starter/pom.xml
@@ -0,0 +1,41 @@
+
+
+ 4.0.0
+
+
+ io.leego
+ mypages-samples
+ 2.0.0
+
+
+ mypages-sample-spring-boot-starter
+ ${project.artifactId}
+
+
+
+ io.leego
+ mypages-spring-boot-starter
+
+
+ org.mybatis.spring.boot
+ mybatis-spring-boot-starter
+
+
+ org.springframework.boot
+ spring-boot-starter
+
+
+ org.springframework.boot
+ spring-boot-starter-jdbc
+
+
+ mysql
+ mysql-connector-java
+
+
+
+
\ No newline at end of file
diff --git a/mypages-samples/mypages-sample-spring-boot-starter/src/main/java/io/leego/mypages/sample/MyPagesApplication.java b/mypages-samples/mypages-sample-spring-boot-starter/src/main/java/io/leego/mypages/sample/MyPagesApplication.java
new file mode 100644
index 0000000..663d7f7
--- /dev/null
+++ b/mypages-samples/mypages-sample-spring-boot-starter/src/main/java/io/leego/mypages/sample/MyPagesApplication.java
@@ -0,0 +1,29 @@
+package io.leego.mypages.sample;
+
+import io.leego.mypages.sample.entity.User;
+import io.leego.mypages.sample.mapper.UserMapper;
+import io.leego.mypages.util.Page;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.ApplicationContext;
+
+import java.util.List;
+
+/**
+ * @author Yihleego
+ */
+@SpringBootApplication
+public class MyPagesApplication {
+ private static final Logger logger = LoggerFactory.getLogger(MyPagesApplication.class);
+
+ public static void main(String[] args) {
+ ApplicationContext applicationContext = SpringApplication.run(MyPagesApplication.class, args);
+ UserMapper userMapper = applicationContext.getBean(UserMapper.class);
+ List list = userMapper.query(1, 10);
+ Page page = Page.of(list);
+ logger.info("{}", page);
+ }
+
+}
diff --git a/mypages-samples/mypages-sample-spring-boot-starter/src/main/java/io/leego/mypages/sample/entity/User.java b/mypages-samples/mypages-sample-spring-boot-starter/src/main/java/io/leego/mypages/sample/entity/User.java
new file mode 100644
index 0000000..f7a6bb5
--- /dev/null
+++ b/mypages-samples/mypages-sample-spring-boot-starter/src/main/java/io/leego/mypages/sample/entity/User.java
@@ -0,0 +1,72 @@
+package io.leego.mypages.sample.entity;
+
+import java.time.LocalDateTime;
+
+/**
+ * @author Yihleego
+ */
+public class User {
+ private Long id;
+ private LocalDateTime createdTime;
+ private LocalDateTime updatedTime;
+ private String username;
+ private String password;
+ private String nickname;
+ private Integer status;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public LocalDateTime getCreatedTime() {
+ return createdTime;
+ }
+
+ public void setCreatedTime(LocalDateTime createdTime) {
+ this.createdTime = createdTime;
+ }
+
+ public LocalDateTime getUpdatedTime() {
+ return updatedTime;
+ }
+
+ public void setUpdatedTime(LocalDateTime updatedTime) {
+ this.updatedTime = updatedTime;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public String getNickname() {
+ return nickname;
+ }
+
+ public void setNickname(String nickname) {
+ this.nickname = nickname;
+ }
+
+ public Integer getStatus() {
+ return status;
+ }
+
+ public void setStatus(Integer status) {
+ this.status = status;
+ }
+}
diff --git a/mypages-samples/mypages-sample-spring-boot-starter/src/main/java/io/leego/mypages/sample/mapper/UserMapper.java b/mypages-samples/mypages-sample-spring-boot-starter/src/main/java/io/leego/mypages/sample/mapper/UserMapper.java
new file mode 100644
index 0000000..106a5f2
--- /dev/null
+++ b/mypages-samples/mypages-sample-spring-boot-starter/src/main/java/io/leego/mypages/sample/mapper/UserMapper.java
@@ -0,0 +1,17 @@
+package io.leego.mypages.sample.mapper;
+
+import io.leego.mypages.sample.entity.User;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
+
+/**
+ * @author Yihleego
+ */
+@Mapper
+public interface UserMapper {
+ @Select("select * from user")
+ List query(@Param("page") Integer page, @Param("size") Integer size);
+}
diff --git a/mypages-samples/mypages-sample-spring-boot-starter/src/main/resources/application.properties b/mypages-samples/mypages-sample-spring-boot-starter/src/main/resources/application.properties
new file mode 100644
index 0000000..5346ab7
--- /dev/null
+++ b/mypages-samples/mypages-sample-spring-boot-starter/src/main/resources/application.properties
@@ -0,0 +1,19 @@
+# port
+server.port=10000
+# name
+spring.application.name=mypages-sample-spring-boot-starter
+# logging
+logging.level.io.leego=debug
+# datasource
+spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
+spring.datasource.url=jdbc:mysql://localhost:3306/mypages?serverTimezone=GMT%2B8
+spring.datasource.username=root
+spring.datasource.password=123456
+# mybatis
+mybatis.configuration.cache-enabled=false
+mybatis.configuration.local-cache-scope=STATEMENT
+mybatis.configuration.jdbc-type-for-null=NULL
+mybatis.configuration.map-underscore-to-camel-case=true
+# mypages
+mypages.page-field=page
+mypages.size-field=size
\ No newline at end of file
diff --git a/mypages-samples/mypages-sample-spring-boot/pom.xml b/mypages-samples/mypages-sample-spring-boot/pom.xml
new file mode 100644
index 0000000..e4cb28e
--- /dev/null
+++ b/mypages-samples/mypages-sample-spring-boot/pom.xml
@@ -0,0 +1,45 @@
+
+
+ 4.0.0
+
+
+ io.leego
+ mypages-samples
+ 2.0.0
+
+
+ mypages-sample-spring-boot
+ ${project.artifactId}
+
+
+
+ io.leego
+ mypages
+
+
+ org.mybatis
+ mybatis
+
+
+ org.mybatis
+ mybatis-spring
+
+
+ org.springframework.boot
+ spring-boot-starter
+
+
+ org.springframework.boot
+ spring-boot-starter-jdbc
+
+
+ mysql
+ mysql-connector-java
+
+
+
+
\ No newline at end of file
diff --git a/mypages-samples/mypages-sample-spring-boot/src/main/java/io/leego/mypages/sample/MyPagesApplication.java b/mypages-samples/mypages-sample-spring-boot/src/main/java/io/leego/mypages/sample/MyPagesApplication.java
new file mode 100644
index 0000000..9177621
--- /dev/null
+++ b/mypages-samples/mypages-sample-spring-boot/src/main/java/io/leego/mypages/sample/MyPagesApplication.java
@@ -0,0 +1,57 @@
+package io.leego.mypages.sample;
+
+import io.leego.mypages.dialect.Database;
+import io.leego.mypages.interceptor.PaginationInterceptor;
+import io.leego.mypages.interceptor.PaginationSettings;
+import io.leego.mypages.sample.entity.User;
+import io.leego.mypages.sample.mapper.UserMapper;
+import io.leego.mypages.util.Page;
+import org.apache.ibatis.plugin.Interceptor;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.mybatis.spring.SqlSessionFactoryBean;
+import org.mybatis.spring.annotation.MapperScan;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+
+import javax.sql.DataSource;
+import java.util.List;
+
+/**
+ * @author Yihleego
+ */
+@MapperScan("io.leego.mypages.sample")
+@SpringBootApplication
+public class MyPagesApplication {
+ private static final Logger logger = LoggerFactory.getLogger(MyPagesApplication.class);
+
+ public static void main(String[] args) {
+ ApplicationContext applicationContext = SpringApplication.run(MyPagesApplication.class, args);
+ UserMapper userMapper = applicationContext.getBean(UserMapper.class);
+ List list = userMapper.query(1, 10);
+ Page page = Page.of(list);
+ logger.info("{}", page);
+ }
+
+ @Bean
+ public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
+ Interceptor[] plugins = new Interceptor[]{paginationInterceptor(dataSource)};
+ SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
+ sqlSessionFactoryBean.setDataSource(dataSource);
+ sqlSessionFactoryBean.setPlugins(plugins);
+ return sqlSessionFactoryBean.getObject();
+ }
+
+ @Bean
+ public PaginationInterceptor paginationInterceptor(DataSource dataSource) {
+ PaginationSettings settings = PaginationSettings.builder()
+ .database(Database.fromDataSource(dataSource))
+ .pageField("page")
+ .sizeField("size")
+ .build();
+ return new PaginationInterceptor(settings);
+ }
+}
diff --git a/mypages-samples/mypages-sample-spring-boot/src/main/java/io/leego/mypages/sample/entity/User.java b/mypages-samples/mypages-sample-spring-boot/src/main/java/io/leego/mypages/sample/entity/User.java
new file mode 100644
index 0000000..f7a6bb5
--- /dev/null
+++ b/mypages-samples/mypages-sample-spring-boot/src/main/java/io/leego/mypages/sample/entity/User.java
@@ -0,0 +1,72 @@
+package io.leego.mypages.sample.entity;
+
+import java.time.LocalDateTime;
+
+/**
+ * @author Yihleego
+ */
+public class User {
+ private Long id;
+ private LocalDateTime createdTime;
+ private LocalDateTime updatedTime;
+ private String username;
+ private String password;
+ private String nickname;
+ private Integer status;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public LocalDateTime getCreatedTime() {
+ return createdTime;
+ }
+
+ public void setCreatedTime(LocalDateTime createdTime) {
+ this.createdTime = createdTime;
+ }
+
+ public LocalDateTime getUpdatedTime() {
+ return updatedTime;
+ }
+
+ public void setUpdatedTime(LocalDateTime updatedTime) {
+ this.updatedTime = updatedTime;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public String getNickname() {
+ return nickname;
+ }
+
+ public void setNickname(String nickname) {
+ this.nickname = nickname;
+ }
+
+ public Integer getStatus() {
+ return status;
+ }
+
+ public void setStatus(Integer status) {
+ this.status = status;
+ }
+}
diff --git a/mypages-samples/mypages-sample-spring-boot/src/main/java/io/leego/mypages/sample/mapper/UserMapper.java b/mypages-samples/mypages-sample-spring-boot/src/main/java/io/leego/mypages/sample/mapper/UserMapper.java
new file mode 100644
index 0000000..106a5f2
--- /dev/null
+++ b/mypages-samples/mypages-sample-spring-boot/src/main/java/io/leego/mypages/sample/mapper/UserMapper.java
@@ -0,0 +1,17 @@
+package io.leego.mypages.sample.mapper;
+
+import io.leego.mypages.sample.entity.User;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
+
+/**
+ * @author Yihleego
+ */
+@Mapper
+public interface UserMapper {
+ @Select("select * from user")
+ List query(@Param("page") Integer page, @Param("size") Integer size);
+}
diff --git a/mypages-samples/mypages-sample-spring-boot/src/main/resources/application.properties b/mypages-samples/mypages-sample-spring-boot/src/main/resources/application.properties
new file mode 100644
index 0000000..e671ccc
--- /dev/null
+++ b/mypages-samples/mypages-sample-spring-boot/src/main/resources/application.properties
@@ -0,0 +1,11 @@
+# port
+server.port=10000
+# name
+spring.application.name=mypages-sample-spring-boot
+# logging
+logging.level.io.leego=debug
+# datasource
+spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
+spring.datasource.url=jdbc:mysql://localhost:3306/mypages?serverTimezone=GMT%2B8
+spring.datasource.username=root
+spring.datasource.password=123456
\ No newline at end of file
diff --git a/mypages-samples/mypages-sample-spring/pom.xml b/mypages-samples/mypages-sample-spring/pom.xml
new file mode 100644
index 0000000..e1b2713
--- /dev/null
+++ b/mypages-samples/mypages-sample-spring/pom.xml
@@ -0,0 +1,69 @@
+
+
+ 4.0.0
+
+
+ io.leego
+ mypages-samples
+ 2.0.0
+
+
+ mypages-sample-spring
+ ${project.artifactId}
+
+
+
+ io.leego
+ mypages
+
+
+ org.mybatis
+ mybatis
+
+
+ org.mybatis
+ mybatis-spring
+
+
+ com.zaxxer
+ HikariCP
+
+
+ mysql
+ mysql-connector-java
+
+
+ org.springframework
+ spring-core
+
+
+ org.springframework
+ spring-beans
+
+
+ org.springframework
+ spring-context
+
+
+ org.springframework
+ spring-context-support
+
+
+ org.springframework
+ spring-oxm
+
+
+ org.springframework
+ spring-tx
+
+
+ org.springframework
+ spring-jdbc
+
+
+
+
\ No newline at end of file
diff --git a/mypages-samples/mypages-sample-spring/src/main/java/io/leego/mypages/sample/MyPagesApplication.java b/mypages-samples/mypages-sample-spring/src/main/java/io/leego/mypages/sample/MyPagesApplication.java
new file mode 100644
index 0000000..99bd5a0
--- /dev/null
+++ b/mypages-samples/mypages-sample-spring/src/main/java/io/leego/mypages/sample/MyPagesApplication.java
@@ -0,0 +1,27 @@
+package io.leego.mypages.sample;
+
+import io.leego.mypages.sample.entity.User;
+import io.leego.mypages.sample.mapper.UserMapper;
+import io.leego.mypages.util.Page;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import java.util.List;
+
+/**
+ * @author Yihleego
+ */
+public class MyPagesApplication {
+ private static final Logger logger = LoggerFactory.getLogger(MyPagesApplication.class);
+
+ public static void main(String[] args) {
+ ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring/spring.xml");
+ UserMapper userMapper = applicationContext.getBean(UserMapper.class);
+ List list = userMapper.query(1, 10);
+ Page page = Page.of(list);
+ logger.info("{}", page);
+ }
+
+}
diff --git a/mypages-samples/mypages-sample-spring/src/main/java/io/leego/mypages/sample/entity/User.java b/mypages-samples/mypages-sample-spring/src/main/java/io/leego/mypages/sample/entity/User.java
new file mode 100644
index 0000000..f7a6bb5
--- /dev/null
+++ b/mypages-samples/mypages-sample-spring/src/main/java/io/leego/mypages/sample/entity/User.java
@@ -0,0 +1,72 @@
+package io.leego.mypages.sample.entity;
+
+import java.time.LocalDateTime;
+
+/**
+ * @author Yihleego
+ */
+public class User {
+ private Long id;
+ private LocalDateTime createdTime;
+ private LocalDateTime updatedTime;
+ private String username;
+ private String password;
+ private String nickname;
+ private Integer status;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public LocalDateTime getCreatedTime() {
+ return createdTime;
+ }
+
+ public void setCreatedTime(LocalDateTime createdTime) {
+ this.createdTime = createdTime;
+ }
+
+ public LocalDateTime getUpdatedTime() {
+ return updatedTime;
+ }
+
+ public void setUpdatedTime(LocalDateTime updatedTime) {
+ this.updatedTime = updatedTime;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public String getNickname() {
+ return nickname;
+ }
+
+ public void setNickname(String nickname) {
+ this.nickname = nickname;
+ }
+
+ public Integer getStatus() {
+ return status;
+ }
+
+ public void setStatus(Integer status) {
+ this.status = status;
+ }
+}
diff --git a/mypages-samples/mypages-sample-spring/src/main/java/io/leego/mypages/sample/mapper/UserMapper.java b/mypages-samples/mypages-sample-spring/src/main/java/io/leego/mypages/sample/mapper/UserMapper.java
new file mode 100644
index 0000000..5070f15
--- /dev/null
+++ b/mypages-samples/mypages-sample-spring/src/main/java/io/leego/mypages/sample/mapper/UserMapper.java
@@ -0,0 +1,15 @@
+package io.leego.mypages.sample.mapper;
+
+import io.leego.mypages.sample.entity.User;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
+
+/**
+ * @author Yihleego
+ */
+public interface UserMapper {
+ @Select("select * from user")
+ List query(@Param("page") Integer page, @Param("size") Integer size);
+}
diff --git a/mypages-samples/mypages-sample-spring/src/main/resources/application.properties b/mypages-samples/mypages-sample-spring/src/main/resources/application.properties
new file mode 100644
index 0000000..723e058
--- /dev/null
+++ b/mypages-samples/mypages-sample-spring/src/main/resources/application.properties
@@ -0,0 +1,4 @@
+spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
+spring.datasource.url=jdbc:mysql://localhost:3306/mypages?serverTimezone=GMT%2B8
+spring.datasource.username=root
+spring.datasource.password=123456
\ No newline at end of file
diff --git a/mypages-samples/mypages-sample-spring/src/main/resources/spring/spring.xml b/mypages-samples/mypages-sample-spring/src/main/resources/spring/spring.xml
new file mode 100644
index 0000000..572501c
--- /dev/null
+++ b/mypages-samples/mypages-sample-spring/src/main/resources/spring/spring.xml
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+
+
+
+
+ classpath:application.properties
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mypages-samples/pom.xml b/mypages-samples/pom.xml
new file mode 100644
index 0000000..12d3b21
--- /dev/null
+++ b/mypages-samples/pom.xml
@@ -0,0 +1,81 @@
+
+
+ 4.0.0
+
+
+ io.leego
+ mypages-parent
+ 2.0.0
+
+
+ mypages-samples
+ ${project.artifactId}
+ pom
+
+
+ mypages-sample-java
+ mypages-sample-spring
+ mypages-sample-spring-boot
+ mypages-sample-spring-boot-starter
+ mypages-sample-mybatis-plus
+
+
+
+ 1.8
+ UTF-8
+ 2.0.0
+ 2.0.0
+ 3.5.7
+ 2.0.6
+ 2.2.0
+ 3.4.3
+ 2.5.3
+
+
+
+
+
+ io.leego
+ mypages
+ ${mypages.version}
+
+
+ io.leego
+ mypages-spring-boot-starter
+ ${mypages-spring-boot-starter.version}
+
+
+ org.mybatis
+ mybatis
+ ${mybatis.version}
+
+
+ org.mybatis
+ mybatis-spring
+ ${mybatis-spring.version}
+
+
+ org.mybatis.spring.boot
+ mybatis-spring-boot-starter
+ ${mybatis-spring-boot-starter.version}
+
+
+ com.baomidou
+ mybatis-plus-boot-starter
+ ${mybatis-plus-boot-starter.version}
+
+
+ org.springframework.boot
+ spring-boot-dependencies
+ ${spring-boot.version}
+ pom
+ import
+
+
+
+
+
\ No newline at end of file
diff --git a/mypages-samples/resources/ddl.sql b/mypages-samples/resources/ddl.sql
new file mode 100644
index 0000000..99e82ee
--- /dev/null
+++ b/mypages-samples/resources/ddl.sql
@@ -0,0 +1,12 @@
+create table if not exists user
+(
+ id bigint primary key auto_increment not null,
+ created_time datetime not null,
+ updated_time datetime null,
+ username varchar(20) not null,
+ password varchar(40) not null,
+ nickname varchar(20) not null,
+ status tinyint default 1 not null
+);
+create unique index uk_user_username on user (username);
+create index idx_user_nickname on user (nickname);
\ No newline at end of file
diff --git a/mypages-samples/resources/dml.sql b/mypages-samples/resources/dml.sql
new file mode 100644
index 0000000..10c4f27
--- /dev/null
+++ b/mypages-samples/resources/dml.sql
@@ -0,0 +1,27 @@
+insert into user (username, password, nickname, created_time)
+values ('jack', '123456', 'Jack', now()),
+ ('charles', '123456', 'Charles', now()),
+ ('bill', '123456', 'Bill', now()),
+ ('vincent', '123456', 'Vincent', now()),
+ ('william', '123456', 'William', now()),
+ ('joseph', '123456', 'Joseph', now()),
+ ('james', '123456', 'James', now()),
+ ('henry', '123456', 'Henry', now()),
+ ('gary', '123456', 'Gary', now()),
+ ('martin', '123456', 'Martin', now()),
+ ('malcolm', '123456', 'Malcolm', now()),
+ ('joan', '123456', 'Joan', now()),
+ ('niki', '123456', 'Niki', now()),
+ ('betty', '123456', 'Betty', now()),
+ ('linda', '123456', 'Linda', now()),
+ ('whitney', '123456', 'Whitney', now()),
+ ('lily', '123456', 'Lily', now()),
+ ('fred', '123456', 'Fred', now()),
+ ('karl', '123456', 'Karl', now()),
+ ('barbara', '123456', 'Barbara', now()),
+ ('elizabeth', '123456', 'Elizabeth', now()),
+ ('helen', '123456', 'Helen', now()),
+ ('katharine', '123456', 'Katharine', now()),
+ ('diana', '123456', 'Diana', now()),
+ ('bob', '123456', 'Bob', now())
+on duplicate key update updated_time = now();
diff --git a/mypages-spring-boot-autoconfigure/pom.xml b/mypages-spring-boot-autoconfigure/pom.xml
new file mode 100644
index 0000000..3d0756a
--- /dev/null
+++ b/mypages-spring-boot-autoconfigure/pom.xml
@@ -0,0 +1,51 @@
+
+
+ 4.0.0
+
+
+ io.leego
+ mypages-parent
+ 2.0.0
+
+
+ mypages-spring-boot-autoconfigure
+ ${project.artifactId}
+ MyPages is a java based, open source pagination plugin for MyBatis that simplifies database paging queries.
+ https://github.com/yihleego/mypages
+
+
+
+ io.leego
+ mypages
+
+
+ org.mybatis
+ mybatis
+ true
+
+
+ org.mybatis.spring.boot
+ mybatis-spring-boot-autoconfigure
+ true
+
+
+ org.springframework.boot
+ spring-boot-autoconfigure
+
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ true
+
+
+ org.springframework.boot
+ spring-boot-autoconfigure-processor
+ true
+
+
+
+
\ No newline at end of file
diff --git a/mypages-spring-boot-autoconfigure/src/main/java/io/leego/mypages/spring/boot/autoconfigure/MyPagesAutoConfiguration.java b/mypages-spring-boot-autoconfigure/src/main/java/io/leego/mypages/spring/boot/autoconfigure/MyPagesAutoConfiguration.java
new file mode 100644
index 0000000..e9481d7
--- /dev/null
+++ b/mypages-spring-boot-autoconfigure/src/main/java/io/leego/mypages/spring/boot/autoconfigure/MyPagesAutoConfiguration.java
@@ -0,0 +1,41 @@
+package io.leego.mypages.spring.boot.autoconfigure;
+
+import io.leego.mypages.dialect.Database;
+import io.leego.mypages.dialect.Dialect;
+import io.leego.mypages.interceptor.PaginationInterceptor;
+import org.apache.ibatis.plugin.Interceptor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import javax.sql.DataSource;
+
+/**
+ * @author Yihleego
+ */
+@Configuration
+@ConditionalOnClass(Interceptor.class)
+@ConditionalOnProperty(value = "mypages.enabled", matchIfMissing = true)
+@EnableConfigurationProperties(MyPagesProperties.class)
+public class MyPagesAutoConfiguration {
+
+ @Bean
+ @ConditionalOnMissingBean(PaginationInterceptor.class)
+ public PaginationInterceptor paginationInterceptor(
+ MyPagesProperties properties,
+ @Autowired(required = false) Dialect dialect,
+ @Autowired(required = false) DataSource dataSource) {
+ if (properties.getDatabase() == null && dataSource != null) {
+ properties.setDatabase(Database.fromDataSource(dataSource));
+ }
+ if (properties.getDatabase() == null && dialect == null) {
+ throw new IllegalArgumentException("Please specify a database type.");
+ }
+ return new PaginationInterceptor(dialect != null ? dialect : properties.getDatabase().newDialect(), properties);
+ }
+
+}
diff --git a/mypages-spring-boot-autoconfigure/src/main/java/io/leego/mypages/spring/boot/autoconfigure/MyPagesProperties.java b/mypages-spring-boot-autoconfigure/src/main/java/io/leego/mypages/spring/boot/autoconfigure/MyPagesProperties.java
new file mode 100644
index 0000000..8fbfb42
--- /dev/null
+++ b/mypages-spring-boot-autoconfigure/src/main/java/io/leego/mypages/spring/boot/autoconfigure/MyPagesProperties.java
@@ -0,0 +1,11 @@
+package io.leego.mypages.spring.boot.autoconfigure;
+
+import io.leego.mypages.interceptor.PaginationSettings;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * @author Yihleego
+ */
+@ConfigurationProperties("mypages")
+public class MyPagesProperties extends PaginationSettings {
+}
diff --git a/mypages-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories b/mypages-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories
new file mode 100644
index 0000000..bfda226
--- /dev/null
+++ b/mypages-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories
@@ -0,0 +1 @@
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=io.leego.mypages.spring.boot.autoconfigure.MyPagesAutoConfiguration
\ No newline at end of file
diff --git a/mypages-spring-boot-starter/README.ZH_CN.md b/mypages-spring-boot-starter/README.ZH_CN.md
new file mode 100644
index 0000000..37ebcf1
--- /dev/null
+++ b/mypages-spring-boot-starter/README.ZH_CN.md
@@ -0,0 +1,89 @@
+# 1. 简介
+
+MyPages是Java实现基于[MyBatis](https://github.com/mybatis/mybatis-3)的开源分页插件,最大程度简化数据库分页查询操作,支持市面上大部分数据库,如:MySQL、PostgreSQL、Oracle、SQLServer等。
+
+# 2. 准备工作
+
+请确保您的Java版本在1.8及以上。
+
+# 3. Maven 依赖
+
+```xml
+
+ io.leego
+ mypages-spring-boot-starter
+ ${mypages-spring-boot-starter.version}
+
+```
+
+# 4. 配置
+
+|Property|Description|Default|
+|:-|:-|:-|
+|mypages.enabled|是否启用分页插件|`true`|
+|mypages.database|指定数据库类型,如:`MySQL`、`PostgreSQL`、`Oracle`等||
+|mypages.count-expr|设置count表达式|`*`|
+|mypages.page-field|从参数字段中获取`page`值||
+|mypages.size-field|从参数字段中获取`size`值||
+|mypages.offset-field|从参数字段中获取`offset`值||
+|mypages.rows-field|从参数字段中获取`rows`值||
+|mypages.count-expr-field|从参数字段中获取count表达式||
+|mypages.count-method-name-field|从参数字段中获取自定义count方法名称||
+|mypages.enable-count-field|从参数字段中判断是否启用count||
+|mypages.skip-query-if-count-equals-zero|是否跳过查询如果结果数量为`0`|`true`|
+|mypages.use-generated-if-count-method-is-missing|是否使用自动生成的count方法如果指定count方法不存在|`true`|
+|mypages.use-graceful-count-sql|是否使用优雅的Count-SQL|`true`|
+|mypages.keep-sorting|是否保留排序|`false`|
+|mypages.default-page|如果`page`为空或小于`1`,则用`default-page`替换`page`,`-1`表示不启用|`-1`|
+|mypages.default-size|如果`size`为空或小于`1`,则用`default-size`替换`size`,`-1`表示不启用|`-1`|
+|mypages.max-page|如果`page`大于`max-page`,则用`max-page`替换`page`,`-1`表示不启用|`-1`|
+|mypages.max-size|如果`size`大于`max-size`,则用`max-size`替换`size`,`-1`表示不启用|`-1`|
+
+### 示例
+
+Properties
+
+```properties
+mypages.enabled=true
+mypages.database=MYSQL
+mypages.count-expr=*
+mypages.page-field=page
+mypages.size-field=size
+mypages.offset-field=offset
+mypages.rows-field=rows
+mypages.count-expr-field=countExpr
+mypages.count-method-name-field=countMethodName
+mypages.enable-count-field=enableCount
+mypages.skip-query-if-count-equals-zero=true
+mypages.use-generated-if-count-method-is-missing=true
+mypages.use-graceful-count-sql=true
+mypages.keep-sorting=false
+mypages.default-page=1
+mypages.default-size=10
+mypages.max-page=10000
+mypages.max-size=10000
+```
+
+Yaml
+
+```yaml
+mypages:
+ enabled: true
+ database: MYSQL
+ count-expr: '*'
+ page-field: page
+ size-field: size
+ offset-field: offset
+ rows-field: rows
+ count-expr-field: countExpr
+ count-method-name-field: countMethodName
+ enable-count-field: enableCount
+ skip-query-if-count-equals-zero: true
+ use-generated-if-count-method-is-missing: true
+ use-graceful-count-sql: true
+ keep-sorting: false
+ default-page: 1
+ default-size: 10
+ max-page: 10000
+ max-size: 10000
+```
\ No newline at end of file
diff --git a/mypages-spring-boot-starter/README.md b/mypages-spring-boot-starter/README.md
new file mode 100644
index 0000000..c9fdd6e
--- /dev/null
+++ b/mypages-spring-boot-starter/README.md
@@ -0,0 +1,89 @@
+# 1. Introduction
+
+MyPages is a java based, open source pagination plugin for [MyBatis](https://github.com/mybatis/mybatis-3) that simplifies database paging queries.
+
+# 2. Getting Started
+
+Please make sure the Java version is 1.8 or above.
+
+# 3. Maven Dependency
+
+```xml
+
+ io.leego
+ mypages-spring-boot-starter
+ ${mypages-spring-boot-starter.version}
+
+```
+
+# 4. Configuration
+
+|Property|Description|Default|
+|:-|:-|:-|
+|mypages.enabled|Whether to enable the plugin|`true`|
+|mypages.database|The database type such as `MySQL`, `PostgreSQL`, `Oracle`, etc||
+|mypages.count-expr|The column name or expression|`*`|
+|mypages.page-field|The `page` field name of the parameter||
+|mypages.size-field|The `size` field name of the parameter||
+|mypages.offset-field|The `offset` field name of the parameter||
+|mypages.rows-field|The `rows` field name of the parameter||
+|mypages.count-expr-field|The count expression field name of the parameter||
+|mypages.count-method-name-field|The `count-method-name` field name of the parameter||
+|mypages.enable-count-field|The `enable-count` field name of the parameter||
+|mypages.skip-query-if-count-equals-zero|Whether to skip query if total value equals zero|`true`|
+|mypages.use-generated-if-count-method-is-missing|Whether to use generated if the specified count method is missing|`true`|
+|mypages.use-graceful-count-sql|Whether to use graceful count-sql|`true`|
+|mypages.keep-sorting|Whether to keep sorting|`false`|
+|mypages.default-page|Replaces the `page` with `default-page` if the `page` is `null` or less than `1`|`-1`|
+|mypages.default-size|Replaces the `size` with `default-size` if the `size` is `null` or less than `1`|`-1`|
+|mypages.max-page|Replaces the `page` with `max-page` if the `page` is greater than `max-page`|`-1`|
+|mypages.max-size|Replaces the `size` with `max-size` if the `size` is greater than `max-size`|`-1`|
+
+### Example
+
+Properties
+
+```properties
+mypages.enabled=true
+mypages.database=MYSQL
+mypages.count-expr=*
+mypages.page-field=page
+mypages.size-field=size
+mypages.offset-field=offset
+mypages.rows-field=rows
+mypages.count-expr-field=countExpr
+mypages.count-method-name-field=countMethodName
+mypages.enable-count-field=enableCount
+mypages.skip-query-if-count-equals-zero=true
+mypages.use-generated-if-count-method-is-missing=true
+mypages.use-graceful-count-sql=true
+mypages.keep-sorting=false
+mypages.default-page=1
+mypages.default-size=10
+mypages.max-page=10000
+mypages.max-size=10000
+```
+
+Yaml
+
+```yaml
+mypages:
+ enabled: true
+ database: MYSQL
+ count-expr: '*'
+ page-field: page
+ size-field: size
+ offset-field: offset
+ rows-field: rows
+ count-expr-field: countExpr
+ count-method-name-field: countMethodName
+ enable-count-field: enableCount
+ skip-query-if-count-equals-zero: true
+ use-generated-if-count-method-is-missing: true
+ use-graceful-count-sql: true
+ keep-sorting: false
+ default-page: 1
+ default-size: 10
+ max-page: 10000
+ max-size: 10000
+```
\ No newline at end of file
diff --git a/mypages-spring-boot-starter/pom.xml b/mypages-spring-boot-starter/pom.xml
index 40a6497..b7b5b16 100644
--- a/mypages-spring-boot-starter/pom.xml
+++ b/mypages-spring-boot-starter/pom.xml
@@ -9,7 +9,7 @@
io.leego
mypages-parent
- 1.1.2
+ 2.0.0
mypages-spring-boot-starter
@@ -20,21 +20,7 @@
io.leego
- mypages
-
-
- org.mybatis
- mybatis
- true
-
-
- org.springframework.boot
- spring-boot-autoconfigure
-
-
- org.springframework.boot
- spring-boot-configuration-processor
- true
+ mypages-spring-boot-autoconfigure
diff --git a/mypages-spring-boot-starter/src/main/java/io/leego/mypages/autoconfigure/MyPagesAutoConfiguration.java b/mypages-spring-boot-starter/src/main/java/io/leego/mypages/autoconfigure/MyPagesAutoConfiguration.java
deleted file mode 100644
index 33f365f..0000000
--- a/mypages-spring-boot-starter/src/main/java/io/leego/mypages/autoconfigure/MyPagesAutoConfiguration.java
+++ /dev/null
@@ -1,85 +0,0 @@
-package io.leego.mypages.autoconfigure;
-
-import io.leego.mypages.dialect.Dialect;
-import io.leego.mypages.interceptor.PaginationInterceptor;
-import io.leego.mypages.interceptor.PaginationSettings;
-import org.apache.ibatis.plugin.Interceptor;
-import org.apache.ibatis.session.SqlSessionFactory;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-import java.util.List;
-
-/**
- * @author Yihleego
- */
-@Configuration
-@ConditionalOnProperty(value = "spring.mypages.enabled", matchIfMissing = true)
-@EnableConfigurationProperties(MyPagesProperties.class)
-public class MyPagesAutoConfiguration {
-
- @Bean
- @ConditionalOnMissingBean(PaginationInterceptor.class)
- public PaginationInterceptor paginationInterceptor(MyPagesProperties properties, @Autowired(required = false) Dialect dialect) {
- if (properties.getSqlDialect() == null && dialect == null) {
- throw new IllegalArgumentException("SqlDialect is required.");
- }
- PaginationSettings settings = PaginationSettings.builder()
- .dialect(dialect)
- .sqlDialect(properties.getSqlDialect())
- .countExpr(properties.getCountExpr())
- .pageField(properties.getPageField())
- .sizeField(properties.getSizeField())
- .offsetField(properties.getOffsetField())
- .rowsField(properties.getRowsField())
- .countExprField(properties.getCountExprField())
- .countMethodNameField(properties.getCountMethodNameField())
- .enableCountField(properties.getEnableCountField())
- .skipQueryIfCountEqualsZero(properties.isSkipQueryIfCountEqualsZero())
- .useGeneratedIfCountMethodIsMissing(properties.isUseGeneratedIfCountMethodIsMissing())
- .defaultPage(properties.getDefaultPage())
- .defaultSize(properties.getDefaultSize())
- .maxPage(properties.getMaxPage())
- .maxSize(properties.getMaxSize())
- .build();
- return new PaginationInterceptor(settings);
- }
-
- @Configuration
- @ConditionalOnBean(SqlSessionFactory.class)
- public static class PaginationInterceptorConfiguration implements InitializingBean {
- @Autowired(required = false)
- private List sqlSessionFactories;
- @Autowired(required = false)
- private PaginationInterceptor paginationInterceptor;
-
- @Override
- public void afterPropertiesSet() {
- if (sqlSessionFactories == null || paginationInterceptor == null) {
- return;
- }
- for (SqlSessionFactory sqlSessionFactory : sqlSessionFactories) {
- List interceptors = sqlSessionFactory.getConfiguration().getInterceptors();
- if (isAbsent(interceptors)) {
- sqlSessionFactory.getConfiguration().addInterceptor(paginationInterceptor);
- }
- }
- }
-
- private boolean isAbsent(List interceptors) {
- for (Interceptor interceptor : interceptors) {
- if (interceptor instanceof PaginationInterceptor) {
- return false;
- }
- }
- return true;
- }
- }
-
-}
diff --git a/mypages-spring-boot-starter/src/main/java/io/leego/mypages/autoconfigure/MyPagesProperties.java b/mypages-spring-boot-starter/src/main/java/io/leego/mypages/autoconfigure/MyPagesProperties.java
deleted file mode 100644
index 5f4d0b9..0000000
--- a/mypages-spring-boot-starter/src/main/java/io/leego/mypages/autoconfigure/MyPagesProperties.java
+++ /dev/null
@@ -1,171 +0,0 @@
-package io.leego.mypages.autoconfigure;
-
-import io.leego.mypages.dialect.SqlDialect;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-/**
- * @author Yihleego
- */
-@ConfigurationProperties("spring.mypages")
-public class MyPagesProperties {
- /** Enabled */
- private boolean enabled = true;
- /** The specified SQL dialect. */
- private SqlDialect sqlDialect;
- /** The column name or expression, the default value is "*"
. */
- private String countExpr;
- /** The page field name. */
- private String pageField;
- /** The size field name. */
- private String sizeField;
- /** The offset field name. */
- private String offsetField;
- /** The rows field name. */
- private String rowsField;
- /** The count expression field name. */
- private String countExprField;
- /** The count method name field name. */
- private String countMethodNameField;
- /** The enable count field name. */
- private String enableCountField;
- /** Whether to skip query if total value equals zero. */
- private boolean skipQueryIfCountEqualsZero = true;
- /** Whether to use generated if the specified count method is missing. */
- private boolean useGeneratedIfCountMethodIsMissing = true;
- /** Replaces page
with defaultPage
if page
is invalid. */
- private int defaultPage = -1;
- /** Replaces size
with defaultSize
if size
is invalid. */
- private int defaultSize = -1;
- /** Replaces page
with maxPage
if page
is invalid. */
- private int maxPage = -1;
- /** Replaces size
with maxSize
if size
is invalid. */
- private int maxSize = -1;
-
- public boolean isEnabled() {
- return enabled;
- }
-
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
-
- public SqlDialect getSqlDialect() {
- return sqlDialect;
- }
-
- public void setSqlDialect(SqlDialect sqlDialect) {
- this.sqlDialect = sqlDialect;
- }
-
- public String getCountExpr() {
- return countExpr;
- }
-
- public void setCountExpr(String countExpr) {
- this.countExpr = countExpr;
- }
-
- public String getPageField() {
- return pageField;
- }
-
- public void setPageField(String pageField) {
- this.pageField = pageField;
- }
-
- public String getSizeField() {
- return sizeField;
- }
-
- public void setSizeField(String sizeField) {
- this.sizeField = sizeField;
- }
-
- public String getOffsetField() {
- return offsetField;
- }
-
- public void setOffsetField(String offsetField) {
- this.offsetField = offsetField;
- }
-
- public String getRowsField() {
- return rowsField;
- }
-
- public void setRowsField(String rowsField) {
- this.rowsField = rowsField;
- }
-
- public String getCountExprField() {
- return countExprField;
- }
-
- public void setCountExprField(String countExprField) {
- this.countExprField = countExprField;
- }
-
- public String getCountMethodNameField() {
- return countMethodNameField;
- }
-
- public void setCountMethodNameField(String countMethodNameField) {
- this.countMethodNameField = countMethodNameField;
- }
-
- public String getEnableCountField() {
- return enableCountField;
- }
-
- public void setEnableCountField(String enableCountField) {
- this.enableCountField = enableCountField;
- }
-
- public boolean isSkipQueryIfCountEqualsZero() {
- return skipQueryIfCountEqualsZero;
- }
-
- public void setSkipQueryIfCountEqualsZero(boolean skipQueryIfCountEqualsZero) {
- this.skipQueryIfCountEqualsZero = skipQueryIfCountEqualsZero;
- }
-
- public boolean isUseGeneratedIfCountMethodIsMissing() {
- return useGeneratedIfCountMethodIsMissing;
- }
-
- public void setUseGeneratedIfCountMethodIsMissing(boolean useGeneratedIfCountMethodIsMissing) {
- this.useGeneratedIfCountMethodIsMissing = useGeneratedIfCountMethodIsMissing;
- }
-
- public int getDefaultPage() {
- return defaultPage;
- }
-
- public void setDefaultPage(int defaultPage) {
- this.defaultPage = defaultPage;
- }
-
- public int getDefaultSize() {
- return defaultSize;
- }
-
- public void setDefaultSize(int defaultSize) {
- this.defaultSize = defaultSize;
- }
-
- public int getMaxPage() {
- return maxPage;
- }
-
- public void setMaxPage(int maxPage) {
- this.maxPage = maxPage;
- }
-
- public int getMaxSize() {
- return maxSize;
- }
-
- public void setMaxSize(int maxSize) {
- this.maxSize = maxSize;
- }
-}
diff --git a/mypages-spring-boot-starter/src/main/resources/META-INF/spring.factories b/mypages-spring-boot-starter/src/main/resources/META-INF/spring.factories
deleted file mode 100644
index da7ee24..0000000
--- a/mypages-spring-boot-starter/src/main/resources/META-INF/spring.factories
+++ /dev/null
@@ -1 +0,0 @@
-org.springframework.boot.autoconfigure.EnableAutoConfiguration=io.leego.mypages.autoconfigure.MyPagesAutoConfiguration
\ No newline at end of file
diff --git a/mypages-test/pom.xml b/mypages-test/pom.xml
new file mode 100644
index 0000000..f905437
--- /dev/null
+++ b/mypages-test/pom.xml
@@ -0,0 +1,46 @@
+
+
+ 4.0.0
+
+
+ io.leego
+ mypages-parent
+ 2.0.0
+
+
+ mypages-test
+ ${project.artifactId}
+
+
+
+ io.leego
+ mypages-spring-boot-starter
+
+
+ org.mybatis.spring.boot
+ mybatis-spring-boot-starter
+
+
+ org.springframework.boot
+ spring-boot-starter
+
+
+ org.springframework.boot
+ spring-boot-starter-jdbc
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ mysql
+ mysql-connector-java
+
+
+
+
\ No newline at end of file
diff --git a/mypages-test/src/main/java/io/leego/mypages/test/MyPagesTestApplication.java b/mypages-test/src/main/java/io/leego/mypages/test/MyPagesTestApplication.java
new file mode 100644
index 0000000..c626b9c
--- /dev/null
+++ b/mypages-test/src/main/java/io/leego/mypages/test/MyPagesTestApplication.java
@@ -0,0 +1,16 @@
+package io.leego.mypages.test;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+/**
+ * @author Yihleego
+ */
+@SpringBootApplication
+public class MyPagesTestApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(MyPagesTestApplication.class, args);
+ }
+
+}
diff --git a/mypages-test/src/main/java/io/leego/mypages/test/dto/CustomClassParam.java b/mypages-test/src/main/java/io/leego/mypages/test/dto/CustomClassParam.java
new file mode 100644
index 0000000..de3bd28
--- /dev/null
+++ b/mypages-test/src/main/java/io/leego/mypages/test/dto/CustomClassParam.java
@@ -0,0 +1,67 @@
+package io.leego.mypages.test.dto;
+
+/**
+ * @author Yihleego
+ */
+public class CustomClassParam {
+ private Integer page;
+ private Integer size;
+ private Long offset;
+ private Integer rows;
+ private Integer status;
+
+ public CustomClassParam() {
+ }
+
+ public CustomClassParam(Integer page, Integer size, Integer status) {
+ this.page = page;
+ this.size = size;
+ this.status = status;
+ }
+
+ public CustomClassParam(Long offset, Integer rows, Integer status) {
+ this.offset = offset;
+ this.rows = rows;
+ this.status = status;
+ }
+
+ public Integer getPage() {
+ return page;
+ }
+
+ public void setPage(Integer page) {
+ this.page = page;
+ }
+
+ public Integer getSize() {
+ return size;
+ }
+
+ public void setSize(Integer size) {
+ this.size = size;
+ }
+
+ public Long getOffset() {
+ return offset;
+ }
+
+ public void setOffset(Long offset) {
+ this.offset = offset;
+ }
+
+ public Integer getRows() {
+ return rows;
+ }
+
+ public void setRows(Integer rows) {
+ this.rows = rows;
+ }
+
+ public Integer getStatus() {
+ return status;
+ }
+
+ public void setStatus(Integer status) {
+ this.status = status;
+ }
+}
diff --git a/mypages-test/src/main/java/io/leego/mypages/test/dto/CustomCountParam.java b/mypages-test/src/main/java/io/leego/mypages/test/dto/CustomCountParam.java
new file mode 100644
index 0000000..8727b98
--- /dev/null
+++ b/mypages-test/src/main/java/io/leego/mypages/test/dto/CustomCountParam.java
@@ -0,0 +1,53 @@
+package io.leego.mypages.test.dto;
+
+/**
+ * @author Yihleego
+ */
+public class CustomCountParam {
+ private Integer page;
+ private Integer size;
+ private String countMethodName;
+ private Integer status;
+
+ public CustomCountParam() {
+ }
+
+ public CustomCountParam(Integer page, Integer size, String countMethodName, Integer status) {
+ this.page = page;
+ this.size = size;
+ this.countMethodName = countMethodName;
+ this.status = status;
+ }
+
+ public Integer getPage() {
+ return page;
+ }
+
+ public void setPage(Integer page) {
+ this.page = page;
+ }
+
+ public Integer getSize() {
+ return size;
+ }
+
+ public void setSize(Integer size) {
+ this.size = size;
+ }
+
+ public String getCountMethodName() {
+ return countMethodName;
+ }
+
+ public void setCountMethodName(String countMethodName) {
+ this.countMethodName = countMethodName;
+ }
+
+ public Integer getStatus() {
+ return status;
+ }
+
+ public void setStatus(Integer status) {
+ this.status = status;
+ }
+}
diff --git a/mypages-test/src/main/java/io/leego/mypages/test/dto/CustomMapParam.java b/mypages-test/src/main/java/io/leego/mypages/test/dto/CustomMapParam.java
new file mode 100644
index 0000000..56e526e
--- /dev/null
+++ b/mypages-test/src/main/java/io/leego/mypages/test/dto/CustomMapParam.java
@@ -0,0 +1,9 @@
+package io.leego.mypages.test.dto;
+
+import java.util.HashMap;
+
+/**
+ * @author Yihleego
+ */
+public class CustomMapParam extends HashMap {
+}
diff --git a/mypages-test/src/main/java/io/leego/mypages/test/dto/PageableParam.java b/mypages-test/src/main/java/io/leego/mypages/test/dto/PageableParam.java
new file mode 100644
index 0000000..2b0f3d4
--- /dev/null
+++ b/mypages-test/src/main/java/io/leego/mypages/test/dto/PageableParam.java
@@ -0,0 +1,73 @@
+package io.leego.mypages.test.dto;
+
+import io.leego.mypages.util.Pageable;
+
+/**
+ * @author Yihleego
+ */
+public class PageableParam implements Pageable {
+ private Integer page;
+ private Integer size;
+ private Long offset;
+ private Integer rows;
+ private Integer status;
+
+ public PageableParam() {
+ }
+
+ public PageableParam(Integer page, Integer size, Integer status) {
+ this.page = page;
+ this.size = size;
+ this.status = status;
+ }
+
+ public PageableParam(Long offset, Integer rows, Integer status) {
+ this.offset = offset;
+ this.rows = rows;
+ this.status = status;
+ }
+
+ @Override
+ public Integer getPage() {
+ return page;
+ }
+
+ public void setPage(Integer page) {
+ this.page = page;
+ }
+
+ @Override
+ public Integer getSize() {
+ return size;
+ }
+
+ public void setSize(Integer size) {
+ this.size = size;
+ }
+
+ @Override
+ public Long getOffset() {
+ return offset;
+ }
+
+ public void setOffset(Long offset) {
+ this.offset = offset;
+ }
+
+ @Override
+ public Integer getRows() {
+ return rows;
+ }
+
+ public void setRows(Integer rows) {
+ this.rows = rows;
+ }
+
+ public Integer getStatus() {
+ return status;
+ }
+
+ public void setStatus(Integer status) {
+ this.status = status;
+ }
+}
diff --git a/mypages-test/src/main/java/io/leego/mypages/test/dto/PaginationFieldParam.java b/mypages-test/src/main/java/io/leego/mypages/test/dto/PaginationFieldParam.java
new file mode 100644
index 0000000..6c06c2a
--- /dev/null
+++ b/mypages-test/src/main/java/io/leego/mypages/test/dto/PaginationFieldParam.java
@@ -0,0 +1,78 @@
+package io.leego.mypages.test.dto;
+
+import io.leego.mypages.annotation.Offset;
+import io.leego.mypages.annotation.Page;
+import io.leego.mypages.annotation.Pagination;
+import io.leego.mypages.annotation.Rows;
+import io.leego.mypages.annotation.Size;
+
+/**
+ * @author Yihleego
+ */
+@Pagination
+public class PaginationFieldParam {
+ @Page
+ private Integer page;
+ @Size
+ private Integer size;
+ @Offset
+ private Long offset;
+ @Rows
+ private Integer rows;
+ private Integer status;
+
+ public PaginationFieldParam() {
+ }
+
+ public PaginationFieldParam(Integer page, Integer size, Integer status) {
+ this.page = page;
+ this.size = size;
+ this.status = status;
+ }
+
+ public PaginationFieldParam(Long offset, Integer rows, Integer status) {
+ this.offset = offset;
+ this.rows = rows;
+ this.status = status;
+ }
+
+ public Integer getPage() {
+ return page;
+ }
+
+ public void setPage(Integer page) {
+ this.page = page;
+ }
+
+ public Integer getSize() {
+ return size;
+ }
+
+ public void setSize(Integer size) {
+ this.size = size;
+ }
+
+ public Long getOffset() {
+ return offset;
+ }
+
+ public void setOffset(Long offset) {
+ this.offset = offset;
+ }
+
+ public Integer getRows() {
+ return rows;
+ }
+
+ public void setRows(Integer rows) {
+ this.rows = rows;
+ }
+
+ public Integer getStatus() {
+ return status;
+ }
+
+ public void setStatus(Integer status) {
+ this.status = status;
+ }
+}
diff --git a/mypages-test/src/main/java/io/leego/mypages/test/dto/PaginationMethodParam.java b/mypages-test/src/main/java/io/leego/mypages/test/dto/PaginationMethodParam.java
new file mode 100644
index 0000000..fe8cb7e
--- /dev/null
+++ b/mypages-test/src/main/java/io/leego/mypages/test/dto/PaginationMethodParam.java
@@ -0,0 +1,78 @@
+package io.leego.mypages.test.dto;
+
+import io.leego.mypages.annotation.Offset;
+import io.leego.mypages.annotation.Page;
+import io.leego.mypages.annotation.Pagination;
+import io.leego.mypages.annotation.Rows;
+import io.leego.mypages.annotation.Size;
+
+/**
+ * @author Yihleego
+ */
+@Pagination
+public class PaginationMethodParam {
+ private Integer page;
+ private Integer size;
+ private Long offset;
+ private Integer rows;
+ private Integer status;
+
+ public PaginationMethodParam() {
+ }
+
+ public PaginationMethodParam(Integer page, Integer size, Integer status) {
+ this.page = page;
+ this.size = size;
+ this.status = status;
+ }
+
+ public PaginationMethodParam(Long offset, Integer rows, Integer status) {
+ this.offset = offset;
+ this.rows = rows;
+ this.status = status;
+ }
+
+ @Page
+ public Integer getPage() {
+ return page;
+ }
+
+ public void setPage(Integer page) {
+ this.page = page;
+ }
+
+ @Size
+ public Integer getSize() {
+ return size;
+ }
+
+ public void setSize(Integer size) {
+ this.size = size;
+ }
+
+ @Offset
+ public Long getOffset() {
+ return offset;
+ }
+
+ public void setOffset(Long offset) {
+ this.offset = offset;
+ }
+
+ @Rows
+ public Integer getRows() {
+ return rows;
+ }
+
+ public void setRows(Integer rows) {
+ this.rows = rows;
+ }
+
+ public Integer getStatus() {
+ return status;
+ }
+
+ public void setStatus(Integer status) {
+ this.status = status;
+ }
+}
diff --git a/mypages-test/src/main/java/io/leego/mypages/test/entity/User.java b/mypages-test/src/main/java/io/leego/mypages/test/entity/User.java
new file mode 100644
index 0000000..f50e35a
--- /dev/null
+++ b/mypages-test/src/main/java/io/leego/mypages/test/entity/User.java
@@ -0,0 +1,85 @@
+package io.leego.mypages.test.entity;
+
+import java.time.LocalDateTime;
+
+/**
+ * @author Yihleego
+ */
+public class User {
+ private Long id;
+ private LocalDateTime createdTime;
+ private LocalDateTime updatedTime;
+ private String username;
+ private String password;
+ private String nickname;
+ private Integer status;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public LocalDateTime getCreatedTime() {
+ return createdTime;
+ }
+
+ public void setCreatedTime(LocalDateTime createdTime) {
+ this.createdTime = createdTime;
+ }
+
+ public LocalDateTime getUpdatedTime() {
+ return updatedTime;
+ }
+
+ public void setUpdatedTime(LocalDateTime updatedTime) {
+ this.updatedTime = updatedTime;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public String getNickname() {
+ return nickname;
+ }
+
+ public void setNickname(String nickname) {
+ this.nickname = nickname;
+ }
+
+ public Integer getStatus() {
+ return status;
+ }
+
+ public void setStatus(Integer status) {
+ this.status = status;
+ }
+
+ @Override
+ public String toString() {
+ return "User{" +
+ "id=" + id +
+ ", createdTime=" + createdTime +
+ ", updatedTime=" + updatedTime +
+ ", username='" + username + '\'' +
+ ", password='" + password + '\'' +
+ ", nickname='" + nickname + '\'' +
+ ", status=" + status +
+ '}';
+ }
+}
\ No newline at end of file
diff --git a/mypages-test/src/main/java/io/leego/mypages/test/enums/UserStatusEnum.java b/mypages-test/src/main/java/io/leego/mypages/test/enums/UserStatusEnum.java
new file mode 100644
index 0000000..2c0903a
--- /dev/null
+++ b/mypages-test/src/main/java/io/leego/mypages/test/enums/UserStatusEnum.java
@@ -0,0 +1,19 @@
+package io.leego.mypages.test.enums;
+
+/**
+ * @author Yihleego
+ */
+public enum UserStatusEnum {
+ DISABLED(0),
+ ENABLED(1);
+
+ private final int code;
+
+ UserStatusEnum(int code) {
+ this.code = code;
+ }
+
+ public int getCode() {
+ return code;
+ }
+}
diff --git a/mypages-test/src/main/java/io/leego/mypages/test/mapper/UserMapper.java b/mypages-test/src/main/java/io/leego/mypages/test/mapper/UserMapper.java
new file mode 100644
index 0000000..37e9922
--- /dev/null
+++ b/mypages-test/src/main/java/io/leego/mypages/test/mapper/UserMapper.java
@@ -0,0 +1,99 @@
+package io.leego.mypages.test.mapper;
+
+import io.leego.mypages.test.dto.CustomClassParam;
+import io.leego.mypages.test.dto.CustomCountParam;
+import io.leego.mypages.test.dto.CustomMapParam;
+import io.leego.mypages.test.dto.PageableParam;
+import io.leego.mypages.test.dto.PaginationFieldParam;
+import io.leego.mypages.test.dto.PaginationMethodParam;
+import io.leego.mypages.test.entity.User;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Yihleego
+ */
+@Mapper
+public interface UserMapper {
+
+ @Select("select * from user where status = #{status}")
+ List findByStatus(@Param("status") Integer status);
+
+ @Select("select count(*) as total from user where status = #{status}")
+ long countByStatus(@Param("status") Integer status);
+
+
+ @Select("select * from user where status = #{status}")
+ List findByStatusWithPageSizeParam(@Param("page") Integer page, @Param("size") Integer size, @Param("status") Integer status);
+
+ @Select("select * from user where status = #{status}")
+ List findByStatusOffsetRowsWithParam(@Param("offset") Long offset, @Param("rows") Integer rows, @Param("status") Integer status);
+
+
+ @Select("select * from user where status = #{status}")
+ List findByPaginationField(PaginationFieldParam param);
+
+ @Select("select * from user where status = #{param.status}")
+ List findByPaginationFieldWithParam0(@Param("param") PaginationFieldParam param);
+
+ @Select("select * from user where status = #{param1.status}")
+ List findByPaginationFieldWithParam1(@Param("param1") PaginationFieldParam param);
+
+
+ @Select("select * from user where status = #{status}")
+ List findByPaginationMethod(PaginationMethodParam param);
+
+ @Select("select * from user where status = #{param.status}")
+ List findByPaginationMethodWithParam0(@Param("param") PaginationMethodParam param);
+
+ @Select("select * from user where status = #{param1.status}")
+ List findByPaginationMethodWithParam1(@Param("param1") PaginationMethodParam param);
+
+
+ @Select("select * from user where status = #{status}")
+ List findByPageable(PageableParam param);
+
+ @Select("select * from user where status = #{param.status}")
+ List findByPageableWithParam0(@Param("param") PageableParam param);
+
+ @Select("select * from user where status = #{param1.status}")
+ List findByPageableWithParam1(@Param("param1") PageableParam param);
+
+
+ @Select("select * from user where status = #{status}")
+ List findByCustomClass(CustomClassParam param);
+
+ @Select("select * from user where status = #{param.status}")
+ List findByCustomClassWithParam0(@Param("param") CustomClassParam param);
+
+ @Select("select * from user where status = #{param1.status}")
+ List findByCustomClassWithParam1(@Param("param1") CustomClassParam param);
+
+
+ @Select("select * from user where status = #{status}")
+ List findByCustomMap(CustomMapParam param);
+
+ @Select("select * from user where status = #{param.status}")
+ List findByCustomMapWithParam0(@Param("param") CustomMapParam param);
+
+ @Select("select * from user where status = #{param1.status}")
+ List findByCustomMapWithParam1(@Param("param1") CustomMapParam param);
+
+
+ @Select("select * from user where status = #{status}")
+ List findByCollectionMap(Map param);
+
+ @Select("select * from user where status = #{map.status}")
+ List findByCollectionMapWithParam0(@Param("map") Map map);
+
+ @Select("select * from user where status = #{param1.status}")
+ List findByCollectionMapWithParam1(@Param("param1") Map map);
+
+
+ @Select("select * from user where status = #{status}")
+ List findByCustomCount(CustomCountParam param);
+}
diff --git a/mypages-test/src/main/resources/application.properties b/mypages-test/src/main/resources/application.properties
new file mode 100644
index 0000000..3b66b93
--- /dev/null
+++ b/mypages-test/src/main/resources/application.properties
@@ -0,0 +1,23 @@
+# port
+server.port=10000
+# name
+spring.application.name=mypages-test
+# logging
+logging.level.io.leego=debug
+# datasource
+spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
+spring.datasource.url=jdbc:mysql://localhost:3306/mypages?serverTimezone=GMT%2B8
+spring.datasource.username=root
+spring.datasource.password=123456
+# mybatis
+mybatis.configuration.cache-enabled=false
+mybatis.configuration.local-cache-scope=STATEMENT
+mybatis.configuration.jdbc-type-for-null=NULL
+mybatis.configuration.map-underscore-to-camel-case=true
+# sql init
+spring.sql.init.mode=ALWAYS
+spring.sql.init.username=root
+spring.sql.init.password=${spring.datasource.password}
+spring.sql.init.schema-locations=classpath*:sql/ddl.sql
+spring.sql.init.data-locations=classpath*:sql/dml.sql
+spring.sql.init.continue-on-error=true
\ No newline at end of file
diff --git a/mypages-test/src/main/resources/sql/ddl.sql b/mypages-test/src/main/resources/sql/ddl.sql
new file mode 100644
index 0000000..99e82ee
--- /dev/null
+++ b/mypages-test/src/main/resources/sql/ddl.sql
@@ -0,0 +1,12 @@
+create table if not exists user
+(
+ id bigint primary key auto_increment not null,
+ created_time datetime not null,
+ updated_time datetime null,
+ username varchar(20) not null,
+ password varchar(40) not null,
+ nickname varchar(20) not null,
+ status tinyint default 1 not null
+);
+create unique index uk_user_username on user (username);
+create index idx_user_nickname on user (nickname);
\ No newline at end of file
diff --git a/mypages-test/src/main/resources/sql/dml.sql b/mypages-test/src/main/resources/sql/dml.sql
new file mode 100644
index 0000000..10c4f27
--- /dev/null
+++ b/mypages-test/src/main/resources/sql/dml.sql
@@ -0,0 +1,27 @@
+insert into user (username, password, nickname, created_time)
+values ('jack', '123456', 'Jack', now()),
+ ('charles', '123456', 'Charles', now()),
+ ('bill', '123456', 'Bill', now()),
+ ('vincent', '123456', 'Vincent', now()),
+ ('william', '123456', 'William', now()),
+ ('joseph', '123456', 'Joseph', now()),
+ ('james', '123456', 'James', now()),
+ ('henry', '123456', 'Henry', now()),
+ ('gary', '123456', 'Gary', now()),
+ ('martin', '123456', 'Martin', now()),
+ ('malcolm', '123456', 'Malcolm', now()),
+ ('joan', '123456', 'Joan', now()),
+ ('niki', '123456', 'Niki', now()),
+ ('betty', '123456', 'Betty', now()),
+ ('linda', '123456', 'Linda', now()),
+ ('whitney', '123456', 'Whitney', now()),
+ ('lily', '123456', 'Lily', now()),
+ ('fred', '123456', 'Fred', now()),
+ ('karl', '123456', 'Karl', now()),
+ ('barbara', '123456', 'Barbara', now()),
+ ('elizabeth', '123456', 'Elizabeth', now()),
+ ('helen', '123456', 'Helen', now()),
+ ('katharine', '123456', 'Katharine', now()),
+ ('diana', '123456', 'Diana', now()),
+ ('bob', '123456', 'Bob', now())
+on duplicate key update updated_time = now();
diff --git a/mypages-test/src/test/java/io/leego/mypages/test/specification/CollectionMapTests.java b/mypages-test/src/test/java/io/leego/mypages/test/specification/CollectionMapTests.java
new file mode 100644
index 0000000..3b1c604
--- /dev/null
+++ b/mypages-test/src/test/java/io/leego/mypages/test/specification/CollectionMapTests.java
@@ -0,0 +1,179 @@
+package io.leego.mypages.test.specification;
+
+import io.leego.mypages.interceptor.PaginationInterceptor;
+import io.leego.mypages.test.entity.User;
+import io.leego.mypages.test.enums.UserStatusEnum;
+import io.leego.mypages.test.mapper.UserMapper;
+import io.leego.mypages.util.Page;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * @author Yihleego
+ */
+@SpringBootTest
+public class CollectionMapTests {
+ private static final Logger logger = LoggerFactory.getLogger(CollectionMapTests.class);
+ @Autowired
+ private PaginationInterceptor interceptor;
+ @Autowired
+ private UserMapper userMapper;
+ private List users;
+
+ @BeforeEach
+ public void before() {
+ /* Configuration:
+ mypages.page-field=page
+ mypages.size-field=size
+ mypages.offset-field=offset
+ mypages.rows-field=rows*/
+ interceptor.getSettings().setPageField("page");
+ interceptor.getSettings().setSizeField("size");
+ interceptor.getSettings().setOffsetField("offset");
+ interceptor.getSettings().setRowsField("rows");
+ users = userMapper.findByStatus(UserStatusEnum.ENABLED.getCode());
+ }
+
+
+ @Test
+ public void findByCollectionMapPageSize() {
+ pageSizeFind(userMapper::findByCollectionMap, pageSizeMap());
+ }
+
+ @Test
+ public void findByCollectionMapWithParam0PageSize() {
+ pageSizeFind(userMapper::findByCollectionMapWithParam0, pageSizeMap());
+ }
+
+ @Test
+ public void findByCollectionMapWithParam1PageSize() {
+ pageSizeFind(userMapper::findByCollectionMapWithParam1, pageSizeMap());
+ }
+
+
+ @Test
+ public void findByCollectionMapOffsetRows() {
+ offsetRowsFind(userMapper::findByCollectionMap, offsetRowsMap());
+ }
+
+ @Test
+ public void findByCollectionMapWithParam0OffsetRows() {
+ offsetRowsFind(userMapper::findByCollectionMapWithParam0, offsetRowsMap());
+ }
+
+ @Test
+ public void findByCollectionMapWithParam1OffsetRows() {
+ offsetRowsFind(userMapper::findByCollectionMapWithParam1, offsetRowsMap());
+ }
+
+
+ @Test
+ public void findByCollectionMapPageSizeLoop() {
+ pageSizeLoop(userMapper::findByCollectionMap, pageSizeMap());
+ }
+
+ @Test
+ public void findByCollectionMapWithParam0PageSizeLoop() {
+ pageSizeLoop(userMapper::findByCollectionMapWithParam0, pageSizeMap());
+ }
+
+ @Test
+ public void findByCollectionMapWithParam1PageSizeLoop() {
+ pageSizeLoop(userMapper::findByCollectionMapWithParam1, pageSizeMap());
+ }
+
+
+ @Test
+ public void findByCollectionMapOffsetRowsLoop() {
+ offsetRowsLoop(userMapper::findByCollectionMap, offsetRowsMap());
+ }
+
+ @Test
+ public void findByCollectionMapWithParam0OffsetRowsLoop() {
+ offsetRowsLoop(userMapper::findByCollectionMapWithParam0, offsetRowsMap());
+ }
+
+ @Test
+ public void findByCollectionMapWithParam1OffsetRowsLoop() {
+ offsetRowsLoop(userMapper::findByCollectionMapWithParam1, offsetRowsMap());
+ }
+
+
+ public Page pageSizeFind(Function> function, T param) {
+ List list = function.apply(param);
+ Page page = Page.of(list);
+ logger.debug("{}", page);
+ Assertions.assertEquals(users.size(), page.getTotal());
+ Assertions.assertTrue(page.isPaged() && !page.isEmpty());
+ Assertions.assertTrue(page.getNext()
+ ? Objects.equals(param.get("size"), page.getList().size())
+ : Objects.equals(param.get("size"), page.getSize()));
+ Assertions.assertEquals(page.getPage(), param.get("page"));
+ return page;
+ }
+
+ public Page offsetRowsFind(Function> function, T param) {
+ List list = function.apply(param);
+ Page page = Page.of(list);
+ logger.debug("{}", page);
+ Assertions.assertEquals(users.size(), page.getTotal());
+ Assertions.assertTrue(page.isPaged() && !page.isEmpty());
+ Assertions.assertTrue(page.getNext()
+ ? Objects.equals(param.get("rows"), page.getList().size())
+ : Objects.equals(param.get("rows"), page.getSize()));
+ Assertions.assertEquals((long) (page.getPage() - 1) * page.getSize(), param.get("offset"));
+ return page;
+ }
+
+ public void pageSizeLoop(Function> function, T param) {
+ int i = 1;
+ while (true) {
+ param.put("page", i);
+ Page page = pageSizeFind(function, param);
+ if (!page.getNext()) {
+ break;
+ }
+ i++;
+ }
+ }
+
+ public void offsetRowsLoop(Function> function, T param) {
+ long i = 0;
+ while (true) {
+ param.put("offset", i);
+ Page page = offsetRowsFind(function, param);
+ if (!page.getNext()) {
+ break;
+ }
+ i += (int) param.get("rows");
+ }
+ }
+
+ public Map pageSizeMap() {
+ Map map = new HashMap<>();
+ map.put("page", 1);
+ map.put("size", 10);
+ map.put("status", UserStatusEnum.ENABLED.getCode());
+ return map;
+ }
+
+ public Map offsetRowsMap() {
+ Map map = new HashMap<>();
+ map.put("offset", 0L);
+ map.put("rows", 10);
+ map.put("status", UserStatusEnum.ENABLED.getCode());
+ return map;
+ }
+
+}
diff --git a/mypages-test/src/test/java/io/leego/mypages/test/specification/CustomClassTests.java b/mypages-test/src/test/java/io/leego/mypages/test/specification/CustomClassTests.java
new file mode 100644
index 0000000..88b3d87
--- /dev/null
+++ b/mypages-test/src/test/java/io/leego/mypages/test/specification/CustomClassTests.java
@@ -0,0 +1,173 @@
+package io.leego.mypages.test.specification;
+
+import io.leego.mypages.interceptor.PaginationInterceptor;
+import io.leego.mypages.test.dto.CustomClassParam;
+import io.leego.mypages.test.entity.User;
+import io.leego.mypages.test.enums.UserStatusEnum;
+import io.leego.mypages.test.mapper.UserMapper;
+import io.leego.mypages.util.Page;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * @author Yihleego
+ */
+@SpringBootTest
+public class CustomClassTests {
+ private static final Logger logger = LoggerFactory.getLogger(CustomClassTests.class);
+ @Autowired
+ private PaginationInterceptor interceptor;
+ @Autowired
+ private UserMapper userMapper;
+ private List users;
+
+ @BeforeEach
+ public void before() {
+ /* Configuration:
+ mypages.page-field=page
+ mypages.size-field=size
+ mypages.offset-field=offset
+ mypages.rows-field=rows*/
+ interceptor.getSettings().setPageField("page");
+ interceptor.getSettings().setSizeField("size");
+ interceptor.getSettings().setOffsetField("offset");
+ interceptor.getSettings().setRowsField("rows");
+ users = userMapper.findByStatus(UserStatusEnum.ENABLED.getCode());
+ }
+
+
+ @Test
+ public void findByCustomClassPageSize() {
+ pageSizeFind(userMapper::findByCustomClass,
+ new CustomClassParam(1, 10, UserStatusEnum.ENABLED.getCode()));
+ }
+
+ @Test
+ public void findByCustomClassWithParam0PageSize() {
+ pageSizeFind(userMapper::findByCustomClassWithParam0,
+ new CustomClassParam(1, 10, UserStatusEnum.ENABLED.getCode()));
+ }
+
+ @Test
+ public void findByCustomClassWithParam1PageSize() {
+ pageSizeFind(userMapper::findByCustomClassWithParam1,
+ new CustomClassParam(1, 10, UserStatusEnum.ENABLED.getCode()));
+ }
+
+
+ @Test
+ public void findByCustomClassOffsetRows() {
+ offsetRowsFind(userMapper::findByCustomClass,
+ new CustomClassParam(0L, 10, UserStatusEnum.ENABLED.getCode()));
+ }
+
+ @Test
+ public void findByCustomClassWithParam0OffsetRows() {
+ offsetRowsFind(userMapper::findByCustomClassWithParam0,
+ new CustomClassParam(0L, 10, UserStatusEnum.ENABLED.getCode()));
+ }
+
+ @Test
+ public void findByCustomClassWithParam1OffsetRows() {
+ offsetRowsFind(userMapper::findByCustomClassWithParam1,
+ new CustomClassParam(0L, 10, UserStatusEnum.ENABLED.getCode()));
+ }
+
+
+ @Test
+ public void findByCustomClassPageSizeLoop() {
+ pageSizeLoop(userMapper::findByCustomClass,
+ new CustomClassParam(1, 10, UserStatusEnum.ENABLED.getCode()));
+ }
+
+ @Test
+ public void findByCustomClassWithParam0PageSizeLoop() {
+ pageSizeLoop(userMapper::findByCustomClassWithParam0,
+ new CustomClassParam(1, 10, UserStatusEnum.ENABLED.getCode()));
+ }
+
+ @Test
+ public void findByCustomClassWithParam1PageSizeLoop() {
+ pageSizeLoop(userMapper::findByCustomClassWithParam1,
+ new CustomClassParam(1, 10, UserStatusEnum.ENABLED.getCode()));
+ }
+
+
+ @Test
+ public void findByCustomClassOffsetRowsLoop() {
+ offsetRowsLoop(userMapper::findByCustomClass,
+ new CustomClassParam(0L, 10, UserStatusEnum.ENABLED.getCode()));
+ }
+
+ @Test
+ public void findByCustomClassWithParam0OffsetRowsLoop() {
+ offsetRowsLoop(userMapper::findByCustomClassWithParam0,
+ new CustomClassParam(0L, 10, UserStatusEnum.ENABLED.getCode()));
+ }
+
+ @Test
+ public void findByCustomClassWithParam1OffsetRowsLoop() {
+ offsetRowsLoop(userMapper::findByCustomClassWithParam1,
+ new CustomClassParam(0L, 10, UserStatusEnum.ENABLED.getCode()));
+ }
+
+
+ public Page pageSizeFind(Function> function, T param) {
+ List list = function.apply(param);
+ Page page = Page.of(list);
+ logger.debug("{}", page);
+ Assertions.assertEquals(users.size(), page.getTotal());
+ Assertions.assertTrue(page.isPaged() && !page.isEmpty());
+ Assertions.assertTrue(page.getNext()
+ ? Objects.equals(param.getSize(), page.getList().size())
+ : Objects.equals(param.getSize(), page.getSize()));
+ Assertions.assertEquals(page.getPage(), param.getPage());
+ return page;
+ }
+
+ public Page offsetRowsFind(Function> function, T param) {
+ List list = function.apply(param);
+ Page page = Page.of(list);
+ logger.debug("{}", page);
+ Assertions.assertEquals(users.size(), page.getTotal());
+ Assertions.assertTrue(page.isPaged() && !page.isEmpty());
+ Assertions.assertTrue(page.getNext()
+ ? Objects.equals(param.getRows(), page.getList().size())
+ : Objects.equals(param.getRows(), page.getSize()));
+ Assertions.assertEquals((long) (page.getPage() - 1) * page.getSize(), param.getOffset());
+ return page;
+ }
+
+ public void pageSizeLoop(Function> function, T param) {
+ int i = 1;
+ while (true) {
+ param.setPage(i);
+ Page page = pageSizeFind(function, param);
+ if (!page.getNext()) {
+ break;
+ }
+ i++;
+ }
+ }
+
+ public void offsetRowsLoop(Function> function, T param) {
+ long i = 0;
+ while (true) {
+ param.setOffset(i);
+ Page page = offsetRowsFind(function, param);
+ if (!page.getNext()) {
+ break;
+ }
+ i += param.getRows();
+ }
+ }
+}
diff --git a/mypages-test/src/test/java/io/leego/mypages/test/specification/CustomCountTests.java b/mypages-test/src/test/java/io/leego/mypages/test/specification/CustomCountTests.java
new file mode 100644
index 0000000..d2e0c92
--- /dev/null
+++ b/mypages-test/src/test/java/io/leego/mypages/test/specification/CustomCountTests.java
@@ -0,0 +1,59 @@
+package io.leego.mypages.test.specification;
+
+import io.leego.mypages.interceptor.PaginationInterceptor;
+import io.leego.mypages.test.dto.CustomCountParam;
+import io.leego.mypages.test.entity.User;
+import io.leego.mypages.test.enums.UserStatusEnum;
+import io.leego.mypages.test.mapper.UserMapper;
+import io.leego.mypages.util.Page;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * @author Yihleego
+ */
+@SpringBootTest
+public class CustomCountTests {
+ private static final Logger logger = LoggerFactory.getLogger(CustomClassTests.class);
+ @Autowired
+ private PaginationInterceptor interceptor;
+ @Autowired
+ private UserMapper userMapper;
+ private List users;
+
+ @BeforeEach
+ public void before() {
+ /* Configuration:
+ mypages.page-field=page
+ mypages.size-field=size
+ mypages.count-method-name-field=countMethodName*/
+ interceptor.getSettings().setPageField("page");
+ interceptor.getSettings().setSizeField("size");
+ interceptor.getSettings().setCountMethodNameField("countMethodName");
+ users = userMapper.findByStatus(UserStatusEnum.ENABLED.getCode());
+ }
+
+
+ @Test
+ public void findByCustomCount() {
+ CustomCountParam param = new CustomCountParam(1, 10, "countByStatus", UserStatusEnum.ENABLED.getCode());
+ List list = userMapper.findByCustomCount(param);
+ Page page = Page.of(list);
+ logger.debug("{}", page);
+ Assertions.assertEquals(users.size(), page.getTotal());
+ Assertions.assertTrue(page.isPaged() && !page.isEmpty());
+ Assertions.assertTrue(page.getNext()
+ ? Objects.equals(param.getSize(), page.getList().size())
+ : Objects.equals(param.getSize(), page.getSize()));
+ Assertions.assertEquals(page.getPage(), param.getPage());
+ }
+
+}
diff --git a/mypages-test/src/test/java/io/leego/mypages/test/specification/CustomMapTests.java b/mypages-test/src/test/java/io/leego/mypages/test/specification/CustomMapTests.java
new file mode 100644
index 0000000..e5c28dc
--- /dev/null
+++ b/mypages-test/src/test/java/io/leego/mypages/test/specification/CustomMapTests.java
@@ -0,0 +1,178 @@
+package io.leego.mypages.test.specification;
+
+import io.leego.mypages.interceptor.PaginationInterceptor;
+import io.leego.mypages.test.dto.CustomMapParam;
+import io.leego.mypages.test.entity.User;
+import io.leego.mypages.test.enums.UserStatusEnum;
+import io.leego.mypages.test.mapper.UserMapper;
+import io.leego.mypages.util.Page;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * @author Yihleego
+ */
+@SpringBootTest
+public class CustomMapTests {
+ private static final Logger logger = LoggerFactory.getLogger(CustomMapTests.class);
+ @Autowired
+ private PaginationInterceptor interceptor;
+ @Autowired
+ private UserMapper userMapper;
+ private List users;
+
+ @BeforeEach
+ public void before() {
+ /* Configuration:
+ mypages.page-field=page
+ mypages.size-field=size
+ mypages.offset-field=offset
+ mypages.rows-field=rows*/
+ interceptor.getSettings().setPageField("page");
+ interceptor.getSettings().setSizeField("size");
+ interceptor.getSettings().setOffsetField("offset");
+ interceptor.getSettings().setRowsField("rows");
+ users = userMapper.findByStatus(UserStatusEnum.ENABLED.getCode());
+ }
+
+
+ @Test
+ public void findByCustomMapPageSize() {
+ pageSizeFind(userMapper::findByCustomMap, pageSizeMap());
+ }
+
+ @Test
+ public void findByCustomMapWithParam0PageSize() {
+ pageSizeFind(userMapper::findByCustomMapWithParam0, pageSizeMap());
+ }
+
+ @Test
+ public void findByCustomMapWithParam1PageSize() {
+ pageSizeFind(userMapper::findByCustomMapWithParam1, pageSizeMap());
+ }
+
+
+ @Test
+ public void findByCustomMapOffsetRows() {
+ offsetRowsFind(userMapper::findByCustomMap, offsetRowsMap());
+ }
+
+ @Test
+ public void findByCustomMapWithParam0OffsetRows() {
+ offsetRowsFind(userMapper::findByCustomMapWithParam0, offsetRowsMap());
+ }
+
+ @Test
+ public void findByCustomMapWithParam1OffsetRows() {
+ offsetRowsFind(userMapper::findByCustomMapWithParam1, offsetRowsMap());
+ }
+
+
+ @Test
+ public void findByCustomMapPageSizeLoop() {
+ pageSizeLoop(userMapper::findByCustomMap, pageSizeMap());
+ }
+
+ @Test
+ public void findByCustomMapWithParam0PageSizeLoop() {
+ pageSizeLoop(userMapper::findByCustomMapWithParam0, pageSizeMap());
+ }
+
+ @Test
+ public void findByCustomMapWithParam1PageSizeLoop() {
+ pageSizeLoop(userMapper::findByCustomMapWithParam1, pageSizeMap());
+ }
+
+
+ @Test
+ public void findByCustomMapOffsetRowsLoop() {
+ offsetRowsLoop(userMapper::findByCustomMap, offsetRowsMap());
+ }
+
+ @Test
+ public void findByCustomMapWithParam0OffsetRowsLoop() {
+ offsetRowsLoop(userMapper::findByCustomMapWithParam0, offsetRowsMap());
+ }
+
+ @Test
+ public void findByCustomMapWithParam1OffsetRowsLoop() {
+ offsetRowsLoop(userMapper::findByCustomMapWithParam1, offsetRowsMap());
+ }
+
+
+ public Page pageSizeFind(Function> function, T param) {
+ List list = function.apply(param);
+ Page page = Page.of(list);
+ logger.debug("{}", page);
+ Assertions.assertEquals(users.size(), page.getTotal());
+ Assertions.assertTrue(page.isPaged() && !page.isEmpty());
+ Assertions.assertTrue(page.getNext()
+ ? Objects.equals(param.get("size"), page.getList().size())
+ : Objects.equals(param.get("size"), page.getSize()));
+ Assertions.assertEquals(page.getPage(), param.get("page"));
+ return page;
+ }
+
+ public Page offsetRowsFind(Function> function, T param) {
+ List list = function.apply(param);
+ Page page = Page.of(list);
+ logger.debug("{}", page);
+ Assertions.assertEquals(users.size(), page.getTotal());
+ Assertions.assertTrue(page.isPaged() && !page.isEmpty());
+ Assertions.assertTrue(page.getNext()
+ ? Objects.equals(param.get("rows"), page.getList().size())
+ : Objects.equals(param.get("rows"), page.getSize()));
+ Assertions.assertEquals((long) (page.getPage() - 1) * page.getSize(), param.get("offset"));
+ return page;
+ }
+
+ public void pageSizeLoop(Function> function, T param) {
+ int i = 1;
+ while (true) {
+ param.put("page", i);
+ Page page = pageSizeFind(function, param);
+ if (!page.getNext()) {
+ break;
+ }
+ i++;
+ }
+ }
+
+ public void offsetRowsLoop(Function> function, T param) {
+ long i = 0;
+ while (true) {
+ param.put("offset", i);
+ Page page = offsetRowsFind(function, param);
+ if (!page.getNext()) {
+ break;
+ }
+ i += (int) param.get("rows");
+ }
+ }
+
+ public CustomMapParam pageSizeMap() {
+ CustomMapParam map = new CustomMapParam();
+ map.put("page", 1);
+ map.put("size", 10);
+ map.put("status", UserStatusEnum.ENABLED.getCode());
+ return map;
+ }
+
+ public CustomMapParam offsetRowsMap() {
+ CustomMapParam map = new CustomMapParam();
+ map.put("offset", 0L);
+ map.put("rows", 10);
+ map.put("status", UserStatusEnum.ENABLED.getCode());
+ return map;
+ }
+
+}
diff --git a/mypages-test/src/test/java/io/leego/mypages/test/specification/MybatisParamTests.java b/mypages-test/src/test/java/io/leego/mypages/test/specification/MybatisParamTests.java
new file mode 100644
index 0000000..ca5be85
--- /dev/null
+++ b/mypages-test/src/test/java/io/leego/mypages/test/specification/MybatisParamTests.java
@@ -0,0 +1,116 @@
+package io.leego.mypages.test.specification;
+
+import io.leego.mypages.interceptor.PaginationInterceptor;
+import io.leego.mypages.test.dto.PageableParam;
+import io.leego.mypages.test.entity.User;
+import io.leego.mypages.test.enums.UserStatusEnum;
+import io.leego.mypages.test.mapper.UserMapper;
+import io.leego.mypages.util.Page;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * @author Yihleego
+ */
+@SpringBootTest
+public class MybatisParamTests {
+ private static final Logger logger = LoggerFactory.getLogger(MybatisParamTests.class);
+ @Autowired
+ private PaginationInterceptor interceptor;
+ @Autowired
+ private UserMapper userMapper;
+ private List users;
+
+ @BeforeEach
+ public void before() {
+ /* Configuration:
+ mypages.page-field=page
+ mypages.size-field=size
+ mypages.offset-field=offset
+ mypages.rows-field=rows*/
+ interceptor.getSettings().setPageField("page");
+ interceptor.getSettings().setSizeField("size");
+ interceptor.getSettings().setOffsetField("offset");
+ interceptor.getSettings().setRowsField("rows");
+ users = userMapper.findByStatus(UserStatusEnum.ENABLED.getCode());
+ }
+
+
+ @Test
+ public void findByStatusWithPageSizeParam() {
+ pageSizeFind(1, 10);
+ }
+
+ @Test
+ public void findByStatusOffsetRowsWithParam() {
+ offsetRowsFind(0L, 10);
+ }
+
+
+ @Test
+ public void findByStatusWithPageSizeParamLoop() {
+ pageSizeLoop();
+ }
+
+ @Test
+ public void findByStatusOffsetRowsWithParamLoop() {
+ offsetRowsLoop();
+ }
+
+
+ public Page pageSizeFind(Integer paramPage, Integer paramSize) {
+ List list = userMapper.findByStatusWithPageSizeParam(paramPage, paramSize, UserStatusEnum.ENABLED.getCode());
+ Page page = Page.of(list);
+ logger.debug("{}", page);
+ Assertions.assertEquals(users.size(), page.getTotal());
+ Assertions.assertTrue(page.isPaged() && !page.isEmpty());
+ Assertions.assertTrue(page.getNext()
+ ? Objects.equals(paramSize, page.getList().size())
+ : Objects.equals(paramSize, page.getSize()));
+ Assertions.assertEquals(page.getPage(), paramPage);
+ return page;
+ }
+
+ public Page