diff --git a/README.ZH_CN.md b/README.ZH_CN.md index 55474de..b75463a 100644 --- a/README.ZH_CN.md +++ b/README.ZH_CN.md @@ -18,7 +18,7 @@ $ mvn clean install ```xml - 0.6.0 + 1.0.0 @@ -31,7 +31,7 @@ $ mvn clean install ### Gradle ```xml -implementation 'io.leego:mypages:0.6.0' +implementation 'io.leego:mypages:1.0.0' ``` ## 数据库 diff --git a/README.md b/README.md index 1386676..afc96eb 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ $ mvn clean install ```xml - 0.6.0 + 1.0.0 @@ -32,7 +32,7 @@ $ mvn clean install ### Gradle ```xml -implementation 'io.leego:mypages:0.6.0' +implementation 'io.leego:mypages:1.0.0' ``` ## Supported diff --git a/docs/STARTER_USERGUIDE.ZH_CN.md b/docs/STARTER_USERGUIDE.ZH_CN.md index 06e568c..6ea6b55 100644 --- a/docs/STARTER_USERGUIDE.ZH_CN.md +++ b/docs/STARTER_USERGUIDE.ZH_CN.md @@ -8,11 +8,11 @@ MyPages是Java实现基于[MyBatis](https://github.com/mybatis/mybatis-3)的开 # 3. 依赖 -## Maven +## 3.1 Maven ```xml - 0.6.0 + 1.0.0 @@ -22,10 +22,10 @@ MyPages是Java实现基于[MyBatis](https://github.com/mybatis/mybatis-3)的开 ``` -## Gradle +## 3.2 Gradle ```xml -implementation 'io.leego:mypages-spring-boot-starter:0.6.0' +implementation 'io.leego:mypages-spring-boot-starter:1.0.0' ``` # 4. 配置 @@ -40,14 +40,14 @@ public class Pageable { private Integer rows; private String countExpr; private String countMethodName; - private boolean enableCount; + private Boolean enableCount; /* getter setter */ } ``` -请注意sql-dialect,它可以是任何SqlDialect且必须被配置。 +请注意sql-dialect必须被配置。 -## Properties +## 4.1 Properties ```properties spring.mypages.enabled=true @@ -68,7 +68,7 @@ spring.mypages.max-page=10000 spring.mypages.max-size=10000 ``` -## Yaml +## 4.2 Yaml ```yaml spring: diff --git a/docs/STARTER_USERGUIDE.md b/docs/STARTER_USERGUIDE.md index 9568195..b9f7856 100644 --- a/docs/STARTER_USERGUIDE.md +++ b/docs/STARTER_USERGUIDE.md @@ -8,11 +8,11 @@ Please make sure the Java version is 1.8 and above. # 3. Dependency -## Maven +## 3.1 Maven ```xml - 0.6.0 + 1.0.0 @@ -22,15 +22,15 @@ Please make sure the Java version is 1.8 and above. ``` -## Gradle +## 3.2 Gradle ```xml -implementation 'io.leego:mypages-spring-boot-starter:0.6.0' +implementation 'io.leego:mypages-spring-boot-starter:1.0.0' ``` # 4. Configuration -Define a class with paging parameters, and configure parameters field names. +Define a class with paging parameters. ```java public class Pageable { @@ -40,14 +40,14 @@ public class Pageable { private Integer rows; private String countExpr; private String countMethodName; - private boolean enableCount; + private Boolean enableCount; /* getter setter */ } ``` -Notice that the sql-dialect is required. It can be any SqlDialect and should be configured. +Please notice that the sql-dialect is required. -## Properties +## 4.1 Properties ```properties spring.mypages.enabled=true @@ -68,7 +68,7 @@ spring.mypages.max-page=10000 spring.mypages.max-size=10000 ``` -## Yaml +## 4.2 Yaml ```yaml spring: diff --git a/docs/USERGUIDE.ZH_CN.md b/docs/USERGUIDE.ZH_CN.md index 0f01269..3beca6d 100644 --- a/docs/USERGUIDE.ZH_CN.md +++ b/docs/USERGUIDE.ZH_CN.md @@ -8,11 +8,11 @@ MyPages是Java实现基于[MyBatis](https://github.com/mybatis/mybatis-3)的开 # 3. 依赖 -## Maven +## 3.1 Maven ```xml - 0.6.0 + 1.0.0 @@ -22,36 +22,33 @@ MyPages是Java实现基于[MyBatis](https://github.com/mybatis/mybatis-3)的开 ``` -## Gradle +## 3.2 Gradle ```xml -implementation 'io.leego:mypages:0.6.0' +implementation 'io.leego:mypages:1.0.0' ``` # 4. 快速设置 -请注意,PaginationInterceptor需要配置SqlDialect,它可以是任何SqlDialect且必须被配置。 +请注意sql-dialect必须被配置。 -## MyBatis SqlSessionFactoryBean +## 4.1 MyBatis SqlSessionFactoryBean ```java -PaginationSettings settings = PaginationSettings.builder() - .sqlDialect(SqlDialect.MYSQL) - .build(); +PaginationSettings settings = new PaginationSettings(SqlDialect.MYSQL); PaginationInterceptor paginationInterceptor = new PaginationInterceptor(settings); Interceptor[] plugins = new Interceptor[]{paginationInterceptor}; SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); - sqlSessionFactoryBean.setDataSource(dataSource); - sqlSessionFactoryBean.setPlugins(plugins); +sqlSessionFactoryBean.setPlugins(plugins); ``` -## Spring +## 4.2 Spring 要在Spring中使用MyBatis,至少需要在Spring应用程序上下文中定义两个东西:SqlSessionFactory对象和至少一个mapper接口。 在MyBatis-Spring中,SqlSessionFactoryBean用于创建SqlSessionFactory。要配置工厂bean,请在Spring配置文件中放入以下内容: -### Spring XML +## 4.3 Spring XML ```xml @@ -68,7 +65,7 @@ SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); ``` -### Spring Boot +## 4.4 Spring Boot ```java @Configuration @@ -84,15 +81,13 @@ public class MybatisConfiguration { @Bean public PaginationInterceptor paginationInterceptor() { - PaginationSettings settings = PaginationSettings.builder() - .sqlDialect(SqlDialect.MYSQL) - .build(); + PaginationSettings settings = new PaginationSettings(SqlDialect.MYSQL); return new PaginationInterceptor(settings); } } ``` -### Spring Boot Starter +## 4.5 Spring Boot Starter > * 请使用: [mypages-spring-boot-starter](STARTER_USERGUIDE.ZH_CN.md) @@ -147,7 +142,7 @@ public class QueryTests { # 6. 启用分页 -## 注解 (推荐) +## 6.1 注解 (推荐) 使用 ```@Pagination```, ```@Page```, ```@Size```, ```@Offset```, ```@Rows``` 注解. @@ -168,43 +163,116 @@ public class Pageable { 更多注解: ```@CountExpr```, ```@CountMethodName```, ```@DisableCount```, ```@DisablePagination```. -## PaginationInterceptor配置 (推荐) +## 6.2 PaginationInterceptor配置 (推荐) + +配置拦截器: + +```java +PaginationSettings settings = PaginationSettings.builder() + .sqlDialect(SqlDialect.MYSQL) + .pageField("page") + .sizeField("size") + .build(); +PaginationInterceptor interceptor = new PaginationInterceptor(settings); +``` + +### 6.2.1 Define classes -使用分页参数定义一个类,并配置参数字段名。 +假设存在一个带分页参数的类: ```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; + + public Pageable(Integer page, Integer size) { + this.page = page; + this.size = size; + } /* getter setter */ } ``` -### 从参数字段中获取page和size值 +假设存在如下定义的Mapper: ```java -PaginationSettings settings = PaginationSettings.builder() - .sqlDialect(SqlDialect.MYSQL) - .pageField("page") - .sizeField("size") - .build(); -PaginationInterceptor interceptor = new PaginationInterceptor(settings); +public interface FooMapper { + @Select("SELECT * FROM foo") + List query(Pageable pageable); +} ``` -### 从参数字段中获取offset和rows值 +调用查询方法: ```java -PaginationSettings settings = PaginationSettings.builder() - .sqlDialect(SqlDialect.MYSQL) - .offsetField("offset") - .rowsField("rows") - .build(); -PaginationInterceptor interceptor = new PaginationInterceptor(settings); +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)); + } +} ``` ### 更多配置 @@ -230,22 +298,18 @@ PaginationSettings settings = PaginationSettings.builder() PaginationInterceptor interceptor = new PaginationInterceptor(settings); ``` -## 继承 ```io.leego.mypages.util.Pageable``` +## 6.3 继承 ```io.leego.mypages.util.Pageable``` 定义一个继承 ```io.leego.mypages.util.Pageable```的类. ```java public class PageableDTO extends io.leego.mypages.util.Pageable { - private String name; - /* getter setter */ } ``` # 7. 使用自定义Count方法 -## 注解 - -假设存在如下定义的类: +## 7.1 注解 ```java @Pagination @@ -266,7 +330,7 @@ public class Pageable { } ``` -## PaginationInterceptor配置 +## 7.2 PaginationInterceptor配置 ```java public class Pageable { @@ -293,7 +357,7 @@ PaginationSettings settings = PaginationSettings.builder() PaginationInterceptor interceptor = new PaginationInterceptor(settings); ``` -## 调用Query和Count方法 +## 7.3 调用Query和Count方法 假设存在如下定义的Mapper: @@ -319,7 +383,7 @@ public class QueryTests { public Page query() { // Specifies the count method name. - return Page.of(fooMapper.query(new Pageable(1, 10, "count"))); + return Page.of(fooMapper.query(new Pageable(1, 10, "count"))); } } ``` @@ -328,20 +392,20 @@ public class QueryTests { 如果分页参数无效,需要合理化参数,可以设置以下参数: -**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。 +**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 = 1000, maxSize = 1000) -public class Pageable {} +@Pagination(defaultPage = 1, defaultSize = 10, maxPage = 10000, maxSize = 10000) +public class Pageable { +} ``` -## PaginationInterceptor配置 +## 8.2 PaginationInterceptor配置 ```java PaginationSettings settings = PaginationSettings.builder() @@ -358,32 +422,31 @@ PaginationInterceptor interceptor = new PaginationInterceptor(settings); 如果调用执行成功结束,它将返回一个```PaginationCollection```实例。 -## 使用包装 ```io.leego.mypages.util.Page``` +## 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)); +Page result = Page.of(fooMapper.query(pageable)).map(foo -> new Bar(foo)); ``` -## 自定义包装类和工具类 +## 9.2 自定义包装类和工具类 参考例子: -#### 包装类 +#### 9.2.1 包装类 ```java public class Pagination implements Serializable { @@ -506,7 +569,7 @@ public class Pagination implements Serializable { } ``` -#### 工具类 +#### 9.2.2 工具类 ```java public final class PageUtils { @@ -575,14 +638,4 @@ public final class PageUtils { } } -``` - -使用自定义包装类和工具类: - -```java -Pagination result = PageUtils.of(fooMapper.query(pageable)); -``` - -```java -Pagination result = PageUtils.of(fooMapper.query(pageable), foo -> new Bar(foo)); ``` \ No newline at end of file diff --git a/docs/USERGUIDE.md b/docs/USERGUIDE.md index 60c1923..96b7c6a 100644 --- a/docs/USERGUIDE.md +++ b/docs/USERGUIDE.md @@ -8,11 +8,11 @@ Please make sure the Java version is 1.8 and above. # 3. Dependency -## Maven +## 3.1 Maven ```xml - 0.6.0 + 1.0.0 @@ -22,36 +22,33 @@ Please make sure the Java version is 1.8 and above. ``` -## Gradle +## 3.2 Gradle ```xml -implementation 'io.leego:mypages:0.6.0' +implementation 'io.leego:mypages:1.0.0' ``` # 4. Quick Setup -Notice that the PaginationInterceptor requires SqlDialect. It can be any SqlDialect and must be configured. +Please notice that the PaginationInterceptor requires SqlDialect. -## MyBatis SqlSessionFactoryBean +## 4.1 MyBatis SqlSessionFactoryBean ```java -PaginationSettings settings = PaginationSettings.builder() - .sqlDialect(SqlDialect.MYSQL) - .build(); +PaginationSettings settings = new PaginationSettings(SqlDialect.MYSQL); PaginationInterceptor paginationInterceptor = new PaginationInterceptor(settings); Interceptor[] plugins = new Interceptor[]{paginationInterceptor}; SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); - sqlSessionFactoryBean.setDataSource(dataSource); - sqlSessionFactoryBean.setPlugins(plugins); +sqlSessionFactoryBean.setPlugins(plugins); ``` -## Spring +## 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: -### Spring XML +## 4.3 Spring XML ```xml @@ -68,7 +65,7 @@ In MyBatis-Spring, an SqlSessionFactoryBean is used to create an SqlSessionFacto ``` -### Spring Boot +## 4.4 Spring Boot ```java @Configuration @@ -84,15 +81,13 @@ public class MybatisConfiguration { @Bean public PaginationInterceptor paginationInterceptor() { - PaginationSettings settings = PaginationSettings.builder() - .sqlDialect(SqlDialect.MYSQL) - .build(); + PaginationSettings settings = new PaginationSettings(SqlDialect.MYSQL); return new PaginationInterceptor(settings); } } ``` -### Spring Boot Starter +## 4.5 Spring Boot Starter > * Please see: [mypages-spring-boot-starter](STARTER_USERGUIDE.md) @@ -147,7 +142,7 @@ public class QueryTests { # 6. Enable Pagination -## Annotations (Recommended) +## 6.1 Annotations (Recommended) Using ```@Pagination```, ```@Page```, ```@Size```, ```@Offset```, ```@Rows``` annotations. @@ -168,50 +163,123 @@ public class Pageable { More annotations: ```@CountExpr```, ```@CountMethodName```, ```@DisableCount```, ```@DisablePagination```. -## PaginationInterceptor Configuration (Recommended) +## 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 classes -Define a class with paging parameters, and configure parameters field names. +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; + + public Pageable(Integer page, Integer size) { + this.page = page; + this.size = size; + } /* getter setter */ } ``` -### Obtains the page and size values from fields +Assume there is a mapper interface defined like the following: ```java -PaginationSettings settings = PaginationSettings.builder() - .sqlDialect(SqlDialect.MYSQL) - .pageField("page") - .sizeField("size") - .build(); -PaginationInterceptor interceptor = new PaginationInterceptor(settings); +public interface FooMapper { + @Select("SELECT * FROM foo") + List query(Pageable pageable); +} ``` -### Obtains the offset and rows values from fields +Call query method: ```java -PaginationSettings settings = PaginationSettings.builder() - .sqlDialect(SqlDialect.MYSQL) - .offsetField("offset") - .rowsField("rows") - .build(); -PaginationInterceptor interceptor = new PaginationInterceptor(settings); +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. + .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. @@ -230,22 +298,18 @@ PaginationSettings settings = PaginationSettings.builder() PaginationInterceptor interceptor = new PaginationInterceptor(settings); ``` -## Extends ```io.leego.mypages.util.Pageable``` +## 6.3 Extends ```io.leego.mypages.util.Pageable``` Define a class extends ```io.leego.mypages.util.Pageable```. ```java public class PageableDTO extends io.leego.mypages.util.Pageable { - private String name; - /* getter setter */ } ``` # 7. Using custom count methods -## Annotations - -Assume there is a class defined like the following: +## 7.1 Annotations ```java @Pagination @@ -266,7 +330,7 @@ public class Pageable { } ``` -## PaginationInterceptor Configuration +## 7.2 PaginationInterceptor Configuration ```java public class Pageable { @@ -293,7 +357,7 @@ PaginationSettings settings = PaginationSettings.builder() PaginationInterceptor interceptor = new PaginationInterceptor(settings); ``` -## Call query and count methods: +## 7.3 Call methods: Assume there is a mapper interface defined like the following: @@ -319,7 +383,7 @@ public class QueryTests { public Page query() { // Specifies the count method name. - return Page.of(fooMapper.query(new Pageable(1, 10, "count"))); + return Page.of(fooMapper.query(new Pageable(1, 10, "count"))); } } ``` @@ -328,20 +392,20 @@ public class QueryTests { 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. +**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. -These can be set up like the following: +## 8.1 Annotations -## Annotations ```java -@Pagination(defaultPage = 1, defaultSize = 10, maxPage = 1000, maxSize = 1000) -public class Pageable {} +@Pagination(defaultPage = 1, defaultSize = 10, maxPage = 10000, maxSize = 10000) +public class Pageable { +} ``` -## PaginationInterceptor Configuration +## 8.2 PaginationInterceptor Configuration ```java PaginationSettings settings = PaginationSettings.builder() @@ -358,32 +422,31 @@ PaginationInterceptor interceptor = new PaginationInterceptor(settings); If the invocation proceed, it will return an instance of the ```PaginationCollection```. -## Using Wrapper Class ```io.leego.mypages.util.Page``` +## 9.1 Using ```io.leego.mypages.util.Page``` -#### Wrap +#### 9.1.1 Wrap ```java Page result = Page.of(fooMapper.query(pageable)); ``` -#### Convert +#### 9.1.2 Convert ```java Page result = Page.of(fooMapper.query(pageable), foo -> new Bar(foo)); ``` -#### Map +#### 9.1.3 Mapping ```java -Page result = Page.of(fooMapper.query(pageable)) - .map(foo -> new Bar(foo)); +Page result = Page.of(fooMapper.query(pageable)).map(foo -> new Bar(foo)); ``` -## Custom Classes & Utils +## 9.2 Custom For example: -#### Wrapper Class +#### 9.2.1 Custom Wrapper Class ```java public class Pagination implements Serializable { @@ -506,7 +569,7 @@ public class Pagination implements Serializable { } ``` -#### Util +#### 9.2.2 Custom Utils ```java public final class PageUtils { @@ -575,14 +638,4 @@ public final class PageUtils { } } -``` - -Finally, use the custom wrapper class and util. - -```java -Pagination result = PageUtils.of(fooMapper.query(pageable)); -``` - -```java -Pagination result = PageUtils.of(fooMapper.query(pageable), foo -> new Bar(foo)); ``` \ No newline at end of file diff --git a/mypages-spring-boot-starter/pom.xml b/mypages-spring-boot-starter/pom.xml index 4447e53..72d5fe7 100644 --- a/mypages-spring-boot-starter/pom.xml +++ b/mypages-spring-boot-starter/pom.xml @@ -9,7 +9,7 @@ io.leego mypages-parent - 0.6.0 + 1.0.0 mypages-spring-boot-starter @@ -32,6 +32,15 @@ mybatis-spring-boot-autoconfigure true + + org.springframework.boot + spring-boot-autoconfigure + + + org.springframework.boot + spring-boot-configuration-processor + true + \ No newline at end of file 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 index 76a92ab..5f4d0b9 100644 --- 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 @@ -28,8 +28,6 @@ public class MyPagesProperties { private String countMethodNameField; /** The enable count field name. */ private String enableCountField; - /** Whether to obtain values from parameter by reflection. */ - private boolean obtainValuesFromFields = false; /** Whether to skip query if total value equals zero. */ private boolean skipQueryIfCountEqualsZero = true; /** Whether to use generated if the specified count method is missing. */ @@ -123,14 +121,6 @@ public void setEnableCountField(String enableCountField) { this.enableCountField = enableCountField; } - public boolean isObtainValuesFromFields() { - return obtainValuesFromFields; - } - - public void setObtainValuesFromFields(boolean obtainValuesFromFields) { - this.obtainValuesFromFields = obtainValuesFromFields; - } - public boolean isSkipQueryIfCountEqualsZero() { return skipQueryIfCountEqualsZero; } diff --git a/mypages/pom.xml b/mypages/pom.xml index 159d554..f70e1e6 100644 --- a/mypages/pom.xml +++ b/mypages/pom.xml @@ -9,7 +9,7 @@ io.leego mypages-parent - 0.6.0 + 1.0.0 mypages diff --git a/mypages/src/main/java/io/leego/mypages/interceptor/PaginationInterceptor.java b/mypages/src/main/java/io/leego/mypages/interceptor/PaginationInterceptor.java index 42bdf2d..b319362 100644 --- a/mypages/src/main/java/io/leego/mypages/interceptor/PaginationInterceptor.java +++ b/mypages/src/main/java/io/leego/mypages/interceptor/PaginationInterceptor.java @@ -64,10 +64,10 @@ public PaginationInterceptor(PaginationSettings settings) { if (settings == null || (settings.getDialect() == null && settings.getSqlDialect() == null)) { throw new IllegalArgumentException("Dialect is not configured."); } - if ((settings.getPageFieldName() != null && settings.getSizeFieldName() != null) - || (settings.getOffsetFieldName() != null && settings.getRowsFieldName() != null)) { - settings.setObtainValuesFromFields(true); - } + // Whether to obtain values from parameter. + settings.setObtainValuesFromFields( + (settings.getPageFieldName() != null && settings.getSizeFieldName() != null) + || (settings.getOffsetFieldName() != null && settings.getRowsFieldName() != null)); this.settings = settings; this.dialect = settings.getDialect() != null ? settings.getDialect() @@ -239,7 +239,6 @@ private BoundSql newBoundSql(MappedStatement ms, BoundSql boundSql, String sql) private boolean isPageable(Object parameter, Class returnType) { if (parameter == null || !Collection.class.isAssignableFrom(returnType) - || isSimpleType(parameter.getClass()) || parameter.getClass().getAnnotation(DisablePagination.class) != null) { return false; } @@ -248,18 +247,6 @@ private boolean isPageable(Object parameter, Class returnType) { || parameter.getClass().getAnnotation(Pagination.class) != null; } - /** - * Returns true if it is a simple type. - * @param type The type - */ - private boolean isSimpleType(Class type) { - return type.isPrimitive() - || Number.class.isAssignableFrom(type) - || CharSequence.class.isAssignableFrom(type) - || type == Character.class - || type == Boolean.class; - } - /** * Returns true when {@link DisableCount} is absent * and enable count equals true. diff --git a/mypages/src/main/java/io/leego/mypages/interceptor/PaginationSettings.java b/mypages/src/main/java/io/leego/mypages/interceptor/PaginationSettings.java index 1384f9b..8a4bd3a 100644 --- a/mypages/src/main/java/io/leego/mypages/interceptor/PaginationSettings.java +++ b/mypages/src/main/java/io/leego/mypages/interceptor/PaginationSettings.java @@ -27,7 +27,7 @@ public final class PaginationSettings { private String countMethodNameFieldName; /** The enable count field name. */ private String enableCountFieldName; - /** Whether to obtain values from parameter by reflection. */ + /** Whether to obtain values from parameter. */ private boolean obtainValuesFromFields = false; /** Whether to skip query if total value equals zero. */ private boolean skipQueryIfCountEqualsZero = true; @@ -45,6 +45,14 @@ public final class PaginationSettings { public PaginationSettings() { } + public PaginationSettings(Dialect dialect) { + this.dialect = dialect; + } + + public PaginationSettings(SqlDialect sqlDialect) { + this.sqlDialect = sqlDialect; + } + public PaginationSettings(Dialect dialect, SqlDialect sqlDialect, String countExpr, String pageFieldName, String sizeFieldName, String offsetFieldName, String rowsFieldName, String countExprFieldName, String countMethodNameFieldName, String enableCountFieldName, boolean obtainValuesFromFields, boolean skipQueryIfCountEqualsZero, boolean useGeneratedIfCountMethodIsMissing, int defaultPage, int defaultSize, int maxPage, int maxSize) { this.dialect = dialect; this.sqlDialect = sqlDialect; diff --git a/pom.xml b/pom.xml index 35926f1..40c777b 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ io.leego mypages-parent - 0.6.0 + 1.0.0 pom ${project.artifactId} MyPages is a java based, open source pagination plugin for MyBatis that simplifies database paging queries. @@ -68,6 +68,7 @@ 3.5.5 2.1.3 1.1.23 + 2.3.1.RELEASE @@ -183,6 +184,16 @@ druid ${druid.version} + + org.springframework.boot + spring-boot-autoconfigure + ${spring-boot.version} + + + org.springframework.boot + spring-boot-configuration-processor + ${spring-boot.version} +