生活随笔
收集整理的這篇文章主要介紹了
ssm 使用 PageHelper 插件分页
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
先增加maven依賴:
<dependency>?? ????<groupId>com.github.pagehelper</groupId>?? ????<artifactId>pagehelper</artifactId>?? ????<version>4.0.0</version>?? </dependency>??
創建mybatis配置文件:mybatis-config.xml內容:
<?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的時候引入配置文件
<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>??
測試代碼:
@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());?? ????????}?? ????}?? }? ? ??
總結
以上是生活随笔為你收集整理的ssm 使用 PageHelper 插件分页的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。