生活随笔
收集整理的這篇文章主要介紹了
Spring + Mybatis 使用 PageHelper 插件分页
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
轉(zhuǎn)載:http://blog.csdn.net/joker_zhou/article/details/50418005
先增加maven依賴(lài):
?
[html]?view plaincopy print?
<dependency>??????<groupId>com.github.pagehelper</groupId>??????<artifactId>pagehelper</artifactId>??????<version>4.0.0</version>??</dependency>??
創(chuàng)建mybatis配置文件:mybatis-config.xml內(nèi)容:
?
?
[html]?view plaincopy print?
<?xml?version="1.0"?encoding="UTF-8"??>??<!DOCTYPE?configuration??PUBLIC?"-//mybatis.org//DTD?Config?3.0//EN"??"http://mybatis.org/dtd/mybatis-3-config.dtd">??<configuration>??????<plugins>??????????????????<plugin?interceptor="com.github.pagehelper.PageHelper">??????????????????????????<property?name="dialect"?value="oracle"/>??????????????????????????????????????????????????<property?name="offsetAsPageNum"?value="true"/>??????????????????????????????????????<property?name="rowBoundsWithCount"?value="true"/>??????????????????????????????????????<property?name="pageSizeZero"?value="true"/>??????????????????????????????????????????????????<property?name="reasonable"?value="true"/>??????????????????????????????????????????????????????????????<property?name="params"?value="pageNum=start;pageSize=limit;"/>??????????????????????????<property?name="supportMethodsArguments"?value="true"/>??????????????????????????<property?name="returnPageInfo"?value="check"/>??????????</plugin>??????</plugins>??</configuration>?? 在Spring配置中配置sqlSessionFactory的時(shí)候引入配置文件
?
?
[html]?view plaincopy print?
<bean?id="sqlSessionFactory"?class="org.mybatis.spring.SqlSessionFactoryBean">??????<property?name="dataSource"?ref="dataSource"?/>??????<property?name="mapperLocations"?value="classpath:joker/itq/im/mapping/*.xml"?/>??????<property?name="configLocation"?value="classpath:mybatis-config.xml"?/>??</bean>?? 測(cè)試代碼:
?
?
[java]?view plaincopy print?
@RunWith(SpringJUnit4ClassRunner.class)??????@ContextConfiguration({"classpath*:/spring-mybatis.xml"})??????public?class?MyBatiasTest?{??????@Resource??????private?ColumnMapper?columnMapper;??????@Test??????public?void?test(){??????????PageHelper.startPage(1,?20);?????????List<Column>?cls?=??columnMapper.selectAll();??????????for?(Column?column?:?cls)?{??????????????System.out.println(column.getBrcoName());??????????}??????}??}??
轉(zhuǎn)載于:https://www.cnblogs.com/ceshi2016/p/7526528.html
總結(jié)
以上是生活随笔為你收集整理的Spring + Mybatis 使用 PageHelper 插件分页的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。