-
Notifications
You must be signed in to change notification settings - Fork 64
Pagination_QuickStart_MyBatis
fangjinuo edited this page May 20, 2020
·
12 revisions
just import dependencies:
<dependency>
<groupId>com.github.fangjinuo.sqlhelper</groupId>
<artifactId>sqlhelper-mybatis-spring-boot-autoconfigure</artifactId>
<version>${sqlhelper.version}</version>
</dependency>
<dependency>
<groupId>com.github.fangjinuo.sqlhelper</groupId>
<artifactId>sqlhelper-mybatis-spring-boot-starter</artifactId>
<version>${sqlhelper.version}</version>
</dependency>
also see sqlhelper-examples module
从 3.0.3 版本开始,需要引入:
<dependency>
<groupId>com.github.fangjinuo.sqlhelper</groupId>
<artifactId>sqlhelper-jsqlparser</artifactId>
<version>${sqlhelper.version}</version>
</dependency>
1.import dependencies:
<dependency>
<groupId>com.github.fangjinuo.sqlhelper</groupId>
<artifactId>sqlhelper-dialect</artifactId>
<version>${sqlhelper.version}</version>
</dependency>
2.config mybatis-config.xml :
<configuration>
...
<databaseIdProvider type="DB_VENDOR">
<property name="SQL Server" value="sqlserver"/>
<property name="DB2" value="db2"/>
<property name="Oracle" value="oracle" />
</databaseIdProvider>
...
<settings>
...
<setting name="defaultScriptingLanguage" value="com.jn.sqlhelper.mybatis.plugins.pagination.CustomScriptLanguageDriver" />
...
</settings>
...
</configuration>
<plugins>
<plugin interceptor="com.jn.sqlhelper.mybatis.plugins.pagination.MybatisPaginationPlugin" />
</plugins>
In this scenario, the mybatis-spring-boot-autoconfigure, sqlhelper-mybatis-spring-boot-autoconfigure will be invalid, so the mybatis application will start fail. So you have to consum your SqlSessionFactoryBean . So when you consum you SqlSessionFactoryBean, you should do like this:
step 1: remove mybatis-pageHelper dependency
step 2: import sqlhelper's:
1. sqlhelper-mybatis
2. sqlhelper-mybatis-spring-boot-autoconfigure
3. sqlhelper-mybatis-spring-boot-starter
4. sqlhelper-mybatis-over-pagehelper
you can use it like this:
@GetMapping
public PagingResult list(){
User queryCondtion = new User();
queryCondtion.setAge(10);
PagingRequest request = SqlPaginations.preparePagination(1,10);
List<User> users = userDao.selectByLimit(queryCondtion); // users is the data list
return request.getResult(); // result has: total ,pagesize, pageNo, maxPage ...
}
just replace mybatis-pagehelper dependencies to sqlhelper-mybatis-over-pagehelper:
<dependency>
<groupId>com.github.fangjinuo.sqlhelper</groupId>
<artifactId>sqlhelper-mybatis-over-pagehelper</artifactId>
<version>${sqlhelper.version}</version>
</dependency>
use it, your code will not make any changes
-
Advanced Usage