spring_boot tab by PageHelper

1. The first step

Import dependence pom.xml

<-! PageHelper Templates ->
 <!--PageHelper模版-->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.5</version>
        </dependency>

 

2. The second step

Application.properties configuration of (in order to prevent the cache, the cache can be turned off during development: spring.thymeleaf.cache = false)

# Set page 
# pagination plug 
pagehelper.helper-dialect = MySQL 
pagehelper.params = COUNT = countSql 
pagehelper.reasonable = to true 
pagehelper.support-Methods to true-arguments The =

 

3. The third step

Use pagination plug-in controller layer, see the code!

@Controller
 public  class ProviderController { 

    Logger Logger = LoggerFactory.getLogger (getClass ()); 

    @Autowired 
    ProviderDao DAO; 

    @Autowired 
    ProviderMapper providerMapper; 


    @GetMapping ( "/ Providers" )
     public String List (the Map <String, Object> Map, Provider Provider , @RequestParam (defaultValue = "1", value = "pageNum" ) Integer pageNum) {
         // pages to eight a 
        PageHelper.startPage (pageNum, 8 ); 

        // query the database to get all suppliers 
        List <provider> providers = providerMapper.getProviders (provider);

        PageInfo<Provider> pageInfo = new PageInfo<Provider>(providers);

        map.put("pageInfo",pageInfo);
 
        return "provider/list";
    }  
  }

4. The front-end thymeleaf template data analysis (* .html files)

<table class="providerTable" cellpadding="0" cellspacing="0" >
            <tr class="firstTr">
                <th width="10%">供应商编码</th>
                <th width="20%">供应商名称</th>
                <th width="10%">联系人</th>
                <th width="10%"><>TH</Phone
                th width="10%">传真</th>
                <th width="10%">创建时间</th>
                <th width="30%">操作</th>
            </tr>
            <tr th:each="p: ${pageInfo.list}">
                <td th:text="${p.pid}">PR</td>
                <td th:text="${p.providerName}">001</td>
                <td th:text="${p.people}"></td>
                <td th:text="${p.phone}">15918230478</td>
                <td th:text="${p.fax}">15918230478</td>
                <td th:text="${#dates.format(p.createDate,'yyyy-MM-dd')}">2015-11-12</td>
                <td>
                    <a th:href="@{/provider/}+${p.pid}" href="view.html"><img th:src="@{/img/read.png}"  alt="查看" title="查看"/></a>
                    <a th:href="@{/provider/}+${p.pid}+'?type=update'" href="update.html"><img th:src="@{/img/xiugai.png}"  alt="修改" title="修改"/></a>
                    <!--  绑定属性    -->
                    <a th:attr="del_uri=@{/provider/}+${p.pid}" href="#"  class="delete"><img th:src="@{/img/schu.png}" alt="删除" title="删除"/></a>
                </td>
            </tr>


            <tr class="firstTr" style="color: blue">
                <th width="10%">&nbsp;------=--</th>
                <th width="20%">&nbsp;----=-----</th>
                <th width="30%"><p style="color: blue">当前 <span th:text="${pageInfo.pageNum}"></span> 页,总 <span th:text="${pageInfo.pages}"></span> 页,共 <span th:text="${pageInfo.total}"></span> 条记录</p></th>
                <th width="10%"><a style="color: blue" th:href="@{/providers}">首页</a></th>
                <th width="10%"><a style="color: blue" th:href="@{/providers(pageNum=${pageInfo.hasPreviousPage}?${pageInfo.prePage}:1)}">上一页</a></th>
                <th width="10%"><a style="color: blue" th:href="@{/providers(pageNum=${pageInfo.hasNextPage}?${pageInfo.nextPage}:${pageInfo.pages})}">下一页</a></th>
                <th width="30%"><a style="color: blue" th:href="@{/providers(pageNum=${pageInfo.pages})}">尾页</a></th>
            </tr>

        </table>

 

The above documents can be configured to test the

End of the test, OK

Guess you like

Origin www.cnblogs.com/pengtaotao/p/12301061.html
Tab
Tab
Tab
Tab