Mybatis paging absolute path writing process detailed explanation


This article mainly introduces the mybatis paging absolute path writing process detailed explanation, the article through the example code introduction is very detailed, for everyone’s study or work has a certain reference learning value, need friends can refer to

There are four steps,

1. Download the jar package. The coordinates of Maven are


2. Add a paging plug-in to mybatis-config.xml, and pay attention to the order of XML’s namespace. Generally, it is at the end.

    <plugin interceptor="com.github.pagehelper.PageInterceptor">
      <!-- Rationalization of paging parameters -- >
      <property name="reasonable" value="true"/>

3. In the controller class that needs to introduce paging, implement it. Before querying, first set the page number and page size of his page. After querying, include it in a pageinfo object and set up several navigation bars. Then return to spring MVC.

  public String getAdmins(@RequestParam(value="pn",defaultValue = "1") Integer pn,Model model) {
    PageHelper.startPage(pn, 10);
    List<Admin> admins = adminService.getAdmins();
    PageInfo<Admin> page = new PageInfo<Admin>(admins, 7);
    model.addAttribute("pageinfo", page);
    return "getAdmins";

4. On the front JSP page, you can simply use ${pageinfo} to display all the information. We can see the details

<c:forEach items="${pageinfo.list }" var="admins">
<td>${ }</td>
<td>${ }</td>
<td>${admins.password }</td>
<td>${ }</td>

<td>${admins.lockFlag }</td>
<td>${admins.role }</td></tr>

Total ${pageinfo. Pages} pages
<c:forEach items="${pageinfo.navigatepageNums }" var="nums">
<a href="${pageContext.request.contextPath }/getAdmins?pn=${nums}" rel="external nofollow" >${nums }</a>

In addition, in the address navigation, if the full path navigation is used

Generally, there are two methods, one is

<a href="${pageContext.request.contextPath }/abc.jsp“>abc</a>

The other is

<% pageContext.setAttribute("APP_PATH", request.getContextPath()); %>

And then quote him

<script type="text/javascript" src="${APP_PATH }/static/js/jquery-1.12.4.min.js"></script>

The above is the whole content of this article, I hope to help you learn, and I hope you can support developer more.

Recommended Today

Large scale distributed storage system: Principle Analysis and architecture practice.pdf

Focus on “Java back end technology stack” Reply to “interview” for full interview information Distributed storage system, which stores data in multiple independent devices. Traditional network storage system uses centralized storage server to store all data. Storage server becomes the bottleneck of system performance and the focus of reliability and security, which can not meet […]