Reprint: http://blog.csdn.net/joker_zhou/article/details/50418005
Add Maven Dependencies First:
[HTML]View PlainCopyprint?
- <dependency>
- <groupId>com.github.pagehelper</groupId>
- <artifactid>pagehelper</artifactid>
- <version>4.0.0</version>
- </Dependency>
Create MyBatis Profile: Mybatis-config.xml content:
[HTML]View PlainCopyprint?
- <? 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 Manager--
- <configuration>
- <plugins>
- <!--Com.github.pagehelper is the package name of the Pagehelper class--
- <plugin interceptor="Com.github.pagehelper.PageHelper">
- <!--4.0.0 later versions can not set this parameter --
- <property name="dialect" value= "oracle"/>
- <!--This parameter defaults to false--
- <!--set to True, the Rowbounds first parameter offset is used as the Pagenum page number -
- <!--and the Pagenum effect in StartPage
- <property name="Offsetaspagenum" value="true"/>
- <!--This parameter defaults to false--
- < When!--is set to True, using rowbounds paging will make a count query --
- <property name="Rowboundswithcount" value="true"/>
- <!--set to True, if pagesize=0 or Rowbounds.limit = 0, all results are queried- -
- <!--(equivalent to not performing a paged query, but the returned result is still page type)--
- <property name="Pagesizezero" value="true"/>
- <!--3.3.0 available-Paging parameter rationalization, default false disabled--
- <!--When rationalizing is enabled, if pagenum<1 queries the first page, Pagenum>pages will query the last page-
- <!--When rationalizing is disabled, if pagenum<1 or pagenum>pages returns empty data--
- <property name="reasonable" value="true"/>
- <!--3.5.0 version available-to support the StartPage (Object params) method--
- <!--added a ' params ' parameter to configure parameter mapping to take values from map or ServletRequest-
- <!--can configure Pagenum,pagesize,count,pagesizezero,reasonable,orderby, do not configure mappings with default values- -
- <!--do not understand the meaning of the premise, do not casually copy the configuration --
- <property name="params" value="PAGENUM=START;PAGESIZE=LIMIT;" />
- <!--support for passing paging parameters via mapper interface Parameters --
- <property name="supportmethodsarguments" value="true"/>
- <!--always returns the PageInfo type, check checks whether the return type is Pageinfo,none returns page--
- <property name="Returnpageinfo" value= "check"/>
- </plugin>
- </plugins>
- </configuration>
Introducing a configuration file when configuring Sqlsessionfactory in the Spring configuration
[HTML]View PlainCopyprint?
- <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>
Test code:
[Java]View PlainCopyprint?
- @RunWith (Springjunit4classrunner. Class)
- @ContextConfiguration ({"Classpath*:/spring-mybatis.xml"})
- Public class Mybatiastest {
- @Resource
- private Columnmapper Columnmapper;
- @Test
- public Void Test () {
- Pagehelper.startpage (1, 20); //Core Paging code
- List<column> cls = Columnmapper.selectall ();
- For (Column column:cls) {
- System.out.println (Column.getbrconame ());
- }
- }
- }
Spring + Mybatis using Pagehelper plug-in pagination