Mybatis-pageHelper for paging, mybatis-pagehelper

Source: Internet
Author: User

Mybatis-pageHelper for paging, mybatis-pagehelper

Mybatis-PageHelpera is a good third-party paging plug-in that supports many databases and almost all mainstream databases.

Github address: https://github.com/pagehelper/Mybatis-PageHelper

Address: https://gitee.com/free/Mybatis_PageHelper

Next, let's try to use this paging plug-in.

  1. Introduce third-party jar
<dependency>  <groupId>com.github.pagehelper</groupId>  <artifactId>pagehelper</artifactId>  <version>5.0.0</version></dependency>
  1. Write interception configuration in application. xml
<Bean id = "demoSqlSessionFactory" class = "org. mybatis. spring. SqlSessionFactoryBean"> <! -- DataSource attribute specifies the connection pool to be used --> <property name = "dataSource" ref = "dataSource"/> <! -- ConfigLocation attribute specifies the core configuration file of mybatis --> <property name = "configLocation" value = "classpath: configuration. xml "/> <property name =" mapperLocations "value =" classpath: com/yihaomen/mybatis/model /*. xml "/> <property name =" typeAliasesPackage "value =" com. yihaomen. mybatis. model "/> <property name =" plugins "> <array> <bean class =" com. github. pagehelper. pageInterceptor "> <property name =" properties "> <value> helperDialect = mysql reasonable = true supportMethodsArguments = true params = count = countSql autoRuntimeDialect = true </value> </property> </bean> </array> </property> </bean>
3. Write the controller Layer
@RequestMapping("/pageList")    public ModelAndView pageUserList(ModelAndView mv,             @RequestParam(required = true, defaultValue = "1") Integer pageNum,             @RequestParam(required = true, defaultValue = "3") Integer pageSize) {PageHelper.startPage(pageNum, pageSize);List<Article> list = articleService.getAllArticles();PageInfo<Article> pageInfo  = new PageInfo<Article>(list);mv.addObject("list", list);mv.addObject("page", pageInfo);mv.setViewName("list2");return mv;}
4. Write the list2.jsp page
<% @ Page language = "java" contentType = "text/html; charset = UTF-8 "pageEncoding =" UTF-8 "%> <% @ taglib prefix =" c "uri =" http://java.sun.com/jsp/jstl/core "%> 

 

Https://gitee.com/huayicompany/springmvc-mybatis

 

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.