1. 程式人生 > >SSM_CRUD新手練習(8)搭建BootStrap分頁頁面

SSM_CRUD新手練習(8)搭建BootStrap分頁頁面

 

經過Spring單元測試模擬請求,我們能夠成功的取出資料,接下來,我們就開始寫用來顯示查詢資料的分頁頁面吧。

我們使用Bootstrap來幫助我們快速開發漂亮的頁面,具體怎麼用可以檢視Bootstrap中文官方文件 https://v3.bootcss.com/getting-started/

  1.把下載的Bootstrap壓縮包解壓到static資料夾。

   

  2.在views資料夾下建立list.jsp分頁頁面。

     Bootstrap官方文件給出了一個簡單引用的基本模板,我們可以看一下。

   

       不難看出我們需要引入三個外掛,而Bootstrap依賴jQuery外掛,所以我們需要自己去下載jQuery外掛,這裡我直接在官網下載的最新的http://jquery.com/download/。

       然後在<head>標籤內引用外掛。

       list.jsp

       

<%@ page contentType="text/html;charset=UTF-8" language
="java" %> <%@page import="java.util.*" %> <html> <head> <!-- 不以/開頭的相對路徑,尋找資源,以當前資源的路徑為標準,經常容易出問題--> <!-- 以/開始的相對路徑,尋找資源,以伺服器的路徑為基準(http://localhost:3306),需要加上專案名才能找到 --> <meta http-equiv="content-Type" content="text/html; charset=UTF-8"><!-- 設定頁面使用的字符集。
--> <link href="${pageContext.request.contextPath}/static/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet"> <script src="${pageContext.request.contextPath}/static/bootstrap-3.3.7-dist/jquery-3.3.1.js"> </script> <script src="${pageContext.request.contextPath}/static/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script> <title>SSM簡單的增刪改查</title> </head> <body> <div class="container"> <!--標題 --> <div class="row"> <div class="col-md-12"> <h2>SSM_CRUD</h2> </div> </div> <!-- 按鈕--> <div class="row"> <div class="col-md-4 col-md-offset-8"> <button class="btn-primary btn-sm">新增</button> <button class="btn-danger btn-sm">刪除</button> </div> </div> <!--顯示錶格資料 --> <div class="row"> <div class="col-md-12"> <table class=" table table-hover"> <tr> <th>#</th> <th>empId</th> <th>gender</th> <th>email</th> <th>操作</th> </tr> <tr> <th>1</th> <th>1012</th> <th></th> <th>2121.com</th> <th> <button class="btn-primary btn-sm"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>編輯</button> <button class="btn-danger btn-sm "><span class="glyphicon glyphicon-trash" aria-hidden="true"></span>刪除</button> </th> </tr> </table> </div> </div> <!-- 顯示分頁資訊--> <div class="row"> <!-- 分頁資訊--> <div class="col-md-6"></div> <!-- 分頁條--> <div class="col-md-6"> <nav aria-label="Page navigation"> <ul class="pagination"> <li><a href="#">首頁</a></li> <li> <a href="#" aria-label="Previous"> <span aria-hidden="true">&laquo;</span> </a> </li> <li><a href="#">1</a></li> <li><a href="#">2</a></li> <li><a href="#">3</a></li> <li><a href="#">4</a></li> <li><a href="#">5</a></li> <li> <a href="#" aria-label="Next"> <span aria-hidden="true">&raquo;</span> </a> </li> <li><a href="#">末頁</a></li> </ul> </nav> </div> </div> </div> </body>

  3.結果