0%
PageHelper使用
1.引入依赖
1 2 3 4 5 6
| <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.2.0</version> </dependency>
|
2.配置
1 2 3 4 5 6 7 8 9 10 11 12
| <plugins> <plugin interceptor="com.github.pagehelper.PageInterceptor"> <property name="helperDialect" value="mysql"/>
<property name="reasonable" value="true"/> </plugin> </plugins>
|
3.使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| AccountDao mapper = sqlSession.getMapper(AccountDao.class);
PageHelper.startPage(3,2);
List<Account> all = mapper.findAll();
PageInfo<Account> pageInfo = new PageInfo<>(all);
int pageNum = pageInfo.getPageNum();
int pageSize = pageInfo.getPageSize();
int size = pageInfo.getSize();
long total = pageInfo.getTotal();
int pages = pageInfo.getPages();
List<Account> list = pageInfo.getList(); System.out.println(all);
|
4.spring整合pagehelper
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="configuration"> <bean class="org.apache.ibatis.session.Configuration"> <property name="mapUnderscoreToCamelCase" value="true"/> </bean> </property> <property name="typeAliasesPackage" value="com.itheima.travel.pojo"/> <property name="plugins"> <array> <bean class="com.github.pagehelper.PageInterceptor"> <property name="properties"> <props> <prop key="helperDialect">mysql</prop> <prop key="reasonable">true</prop> </props> </property> </bean> </array> </property> </bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.itheima.dao"></property> </bean>
|