首先完成分頁
引入PageHelper(之前已經添加過了)
在spring-persist-mybatis.xml配置PageHelper插件
找到AdminMapper.xml完成代碼
完成selectAdminByKeyword
AdminMapper接口中聲明方法
AdminService接口中添加方法
具體實現
AdminHandler中添加的方法
準備admin-page.jsp
添加代碼
<code>pageEncoding="UTF-8"%>
數據列表
<button>style="float: right; margin-left: 10px;">
刪除
/<button>
<button>style="float: right;" onclick="window.location.href='add.html'">
新增
/<button>
<table>
<thead># 賬號 名稱 郵箱地址
操作
/<thead>
<tbody>抱歉!沒有查詢到您要的數據!
<foreach>${myStatus.count } ${admin.loginAcct } ${admin.userName } ${admin.email }
<button>
/<button>
<button>
/<button>
<button>
/<button>
/<foreach>
/<tbody>
<tfoot>
/<tfoot>
/<table>
/<code>
運行查看下
分頁導航條
加入pagination的環境
引入
<code>
/<code>
替換
有個地方我們註釋一下jquery.pagination.js中
帶上關鍵字進行查詢,在admin-page.jsp中
翻頁時保持查詢條件
點擊刪除
調整刪除按鈕
代碼
<code>
添加remove方法(service、serviceimpl)
測試成功
新增
跳轉表單頁面
之前數據庫賬戶沒有加唯一索引,修改下表
ALTER TABLE `t_admin` ADD UNIQUE INDEX(`login_acct`)
調整按鈕admin-page.jsp
添加mvc:view-controller
添加頁面admin-add.jsp
添加代碼
<code>pageEncoding="UTF-8"%>
表單數據data-target="#myModal">
/<code>
編寫handler方法
完成service方法
添加LoginAcctAlreadyInUseException
測試下
更新和新增的思路一致
修改按鈕
<code>
添加頁面
頁面內容
<code>pageEncoding="UTF-8"%>
表單數據data-target="#myModal">
/<code>
編寫handler方法
添加業務方法
同樣添加LoginAcctAlreadyInUseForUpdateException
測試下
Admin-page.jsp所有代碼
<code>pageEncoding="UTF-8"%>
<link>
數據列表
<button>style="float: right; margin-left: 10px;">
刪除
/<button>
<table>
<thead># 賬號 名稱 郵箱地址 操作
/<thead>
<tbody>抱歉!沒有查詢到您要的數據!
<foreach>${myStatus.count } ${admin.loginAcct } ${admin.userName } ${admin.email }
<button>
/<button>
/<foreach>
/<tbody>
<tfoot>
/<tfoot>
/<table>
/<code>
閱讀更多 分享電腦學習 的文章