Spring + Mybatis using Pagehelper plug-in pagination

Source: Internet
Author: User

Reprint: http://blog.csdn.net/joker_zhou/article/details/50418005

Add Maven Dependencies First:

[HTML]View PlainCopyprint?
  1. <dependency>
  2. <groupId>com.github.pagehelper</groupId>
  3. <artifactid>pagehelper</artifactid>
  4. <version>4.0.0</version>
  5. </Dependency>


Create MyBatis Profile: Mybatis-config.xml content:

[HTML]View PlainCopyprint?
  1. <? XML version= "1.0" encoding="UTF-8" ?>
  2. <! DOCTYPE Configuration
  3. Public "-//mybatis.org//dtd Config 3.0//en"
  4. "Http://mybatis.org/dtd/mybatis-3-config.dtd">
  5. <!--Configuration Manager--
  6. <configuration>
  7. <plugins>
  8. <!--Com.github.pagehelper is the package name of the Pagehelper class--
  9. <plugin interceptor="Com.github.pagehelper.PageHelper">
  10. <!--4.0.0 later versions can not set this parameter --
  11. <property name="dialect" value= "oracle"/>
  12. <!--This parameter defaults to false--
  13. <!--set to True, the Rowbounds first parameter offset is used as the Pagenum page number -
  14. <!--and the Pagenum effect in StartPage
  15. <property name="Offsetaspagenum" value="true"/>
  16. <!--This parameter defaults to false--
  17. < When!--is set to True, using rowbounds paging will make a count query --
  18. <property name="Rowboundswithcount" value="true"/>
  19. <!--set to True, if pagesize=0 or Rowbounds.limit = 0, all results are queried- -
  20. <!--(equivalent to not performing a paged query, but the returned result is still page type)--
  21. <property name="Pagesizezero" value="true"/>
  22. <!--3.3.0 available-Paging parameter rationalization, default false disabled--
  23. <!--When rationalizing is enabled, if pagenum<1 queries the first page, Pagenum>pages will query the last page-
  24. <!--When rationalizing is disabled, if pagenum<1 or pagenum>pages returns empty data--
  25. <property name="reasonable" value="true"/>
  26. <!--3.5.0 version available-to support the StartPage (Object params) method--
  27. <!--added a ' params ' parameter to configure parameter mapping to take values from map or ServletRequest-
  28. <!--can configure Pagenum,pagesize,count,pagesizezero,reasonable,orderby, do not configure mappings with default values- -
  29. <!--do not understand the meaning of the premise, do not casually copy the configuration --
  30. <property name="params" value="PAGENUM=START;PAGESIZE=LIMIT;" />
  31. <!--support for passing paging parameters via mapper interface Parameters --
  32. <property name="supportmethodsarguments" value="true"/>
  33. <!--always returns the PageInfo type, check checks whether the return type is Pageinfo,none returns page--
  34. <property name="Returnpageinfo" value= "check"/>
  35. </plugin>
  36. </plugins>
  37. </configuration>

Introducing a configuration file when configuring Sqlsessionfactory in the Spring configuration

[HTML]View PlainCopyprint?
  1. <Bean id= "sqlsessionfactory" class="Org.mybatis.spring.SqlSessionFactoryBean " >
  2. <property name= "dataSource" ref="DataSource" />
  3. <property name= "mapperlocations" value="Classpath:joker/itq/im/mapping/*.xml " />
  4. <property name= "configlocation" value="Classpath:mybatis-config.xml" />
  5. </Bean>

Test code:

[Java]View PlainCopyprint?
    1. @RunWith (Springjunit4classrunner. Class)
    2. @ContextConfiguration ({"Classpath*:/spring-mybatis.xml"})
    3. Public class Mybatiastest {
    4. @Resource
    5. private Columnmapper Columnmapper;
    6. @Test
    7. public Void Test () {
    8. Pagehelper.startpage (1, 20); //Core Paging code
    9. List<column> cls = Columnmapper.selectall ();
    10. For (Column column:cls) {
    11. System.out.println (Column.getbrconame ());
    12. }
    13. }
    14. }

Spring + Mybatis using Pagehelper plug-in pagination

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.