Domestic use of third-party jar pagehelper
Basic attribute values inside
// this page Private int pageNum; // page number Private int pageSize; // number of the current page Private int size; // Since startRow and endRow not common here that a specific usage // be in the page " startRow to display endRow total size of data " // current page is the first element of a row number in the database private int startRow; // this last element in the page line number in the database private int endRow; // total number of records private Long total; // total number of pages private int pages; // result set privateList <T> List; // a former Private int prePage; // Next Private int nextPage; // whether the first page of the Private boolean isFirstPage = false ; // whether the last page of the Private boolean isLastPage = false ; // Is there a previous page Private boolean hasPreviousPage = false ; // if there Next Private boolean hasNextPage = false ; // navigation page number Private intnavigatePages; // all navigation page number Private int [] navigatepageNums; // first page navigation bar Private int navigateFirstPage; // last page navigation bar Private int navigateLastPage;
1. Assign the objects to the container configuration file processing mybatis
<! - put to the IOC Governing SqlSessionFactory -> <bean the above mentioned id = "SqlSessionFactory" class = "org.mybatis.spring.SqlSessionFactoryBean"> <Property name = "dataSource" ref = "dataSource" /> <! - incoming PageHelper plug-in for paging query -> <Property name = "plugins"> <Array> <-! plug incoming objects -> <bean class = "com.github.pagehelper.PageInterceptor"> < name = Property "Properties"> <The props> <prop Key = "helperDialect"> Oracle </ prop> <prop key="reasonable">true</prop> </props> </property> </bean> </array> </property> </bean>
2. I am using jsp page where the page number of the parameters set about
<% - page = 1 & size = 4 paging query -%>
href="${pageContext.request.contextPath}/orders/findAll.do?page=1&size=4">
3. web layer process (partial code) to set a start your page, 4 page shows the number of passed as parameters to
/ * Name = Request parameter name (must be configured) * = Required required, the default is true, i.e., the request must include the parameter, if it does not, an exception is thrown (optional) Default parameters * defaultValue = * * / public ModelAndView the findAll (@RequestParam (name = "Page", required = to true , defaultValue = ". 1") int Page, @ RequestParam (name = "size", required = to true , defaultValue = ". 4") int size ) { ModelAndView Music Videos = new new ModelAndView (); List <the Orders> Orders = service.findAll (Page, size); // PageInfo tab is the bean PageInfo PageInfo = new new PageInfo (Orders); mv.addObject ("pageInfo",pageInfo); mv.setViewName("orders-page-list"); return mv; }
4. Modify Data Frontend display page, because the data is encapsulated you query a list of objects pageInfo
<c:forEach items="${pageInfo.list}" var="orders">
http://git.oschina.net/free/Mybatis_PageHelper jar Download