-
Notifications
You must be signed in to change notification settings - Fork 64
Pagination_QuickStart_MyBatis
fangjinuo edited this page May 25, 2019
·
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
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.github.fangjinuo.sqlhelper.mybatis.plugins.pagination.CustomScriptLanguageDriver" /> ... </settings> ... </configuration> <plugins> <plugin interceptor="com.github.fangjinuo.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:
you can use it like this:
@GetMapping public PagingResult list(){ User queryCondtion = new User(); queryCondtion.setAge(10); PagingRequest request = new PagingRequest() .setPageNo(1) .setPageSize(10); PagingRequestContextHolder.getContext().setPagingRequest(request); List users = userDao.selectByLimit(queryCondtion); request.getResult().setItems(users); return request.getResult(); }
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