Bootstrap和Java分页实例第二篇(3)

package getui.controller; import getui.service.BookService; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @Controller @RequestMapping(value = "/test") public class TestController extends BaseController { /** 日志记录 .*/ private static Logger logger = Logger.getLogger(TestController.class); @Autowired private BookService bookService; @RequestMapping("/test.do") public String test(Model model,String type, @RequestParam(required=false) Integer pageNum, @RequestParam(required=false) Integer pageSize) { Map<String,Object> map = new HashMap<String,Object>(); map.put("type", type); Integer totalCount = bookService.getListCount(); this.initPage(map, pageNum, pageSize, totalCount); List list = this.bookService.getListBook(Integer.valueOf(String.valueOf(map.get("startIndex"))), Integer.valueOf(String.valueOf(map.get("pageSize")))); this.initResult(model, list, map); return "book"; } }

实例-JSP

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="page" uri="/WEB-INF/pager.tld"%> <% String path = request.getContextPath(); %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!DOCTYPE html> <html> <head> <title>测试分页标签</title> <link href="https://www.jb51.net/<%=path%>/css/bootstrap.css"> <link href="https://www.jb51.net/<%=path%>/css/bootstrap-responsive.css"> <script type="text/javascript"> function toDel(id){ var url = "<%=path%>/test/del?id=" + id +"&pageNum=${param.pageNum}&pageSize=${param.pageSize}"; window.location.href = url; } </script> </head> <body> <div> <c:forEach items="${list}" var="item"> <div> <h3><a href="<%=path%>/test/view?id=${item.id}">${item.name}</a></h3> <p> ${item.content} </p> <p> 2013-06-22 22:37&nbsp;&nbsp; <a href="javascript:toDel('${item.id}');">删除</a>&nbsp;&nbsp; <a href="<%=path%>/test/toEdit?id=${item.id}&pageNum=${param.pageNum}&pageSize=${param.pageSize}">编辑</a>&nbsp;&nbsp; </p> </div> </c:forEach> <form method="post" action="<%=path%>/test/test.do"> <input type="hidden" value="${type}"> </form> <page:createPager pageSize="${pageSize}" totalPage="${totalPage}" totalCount="${totalCount}" curPage="${pageNum}" formId="testForm"/> </div> </body> </html>

实例-SQL

/* Navicat MySQL Data Transfer Source Server : 本地库 Source Server Version : 50621 Source Host : localhost:3306 Source Database : test Target Server Type : MYSQL Target Server Version : 50621 File Encoding : 65001 Date: 2016-01-13 12:37:11 */ SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for `book` -- ---------------------------- DROP TABLE IF EXISTS `book`; CREATE TABLE `book` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(20) DEFAULT NULL, `price` int(11) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8; -- ---------------------------- -- Records of book -- ---------------------------- INSERT INTO `book` VALUES ('1', '图书1', '10'); INSERT INTO `book` VALUES ('2', '图书2', '11'); INSERT INTO `book` VALUES ('3', '图书3', '12'); INSERT INTO `book` VALUES ('4', '图书4', '13'); INSERT INTO `book` VALUES ('5', '图书5', '14'); INSERT INTO `book` VALUES ('6', '图书6', '15'); INSERT INTO `book` VALUES ('7', '图书7', '16'); INSERT INTO `book` VALUES ('8', '图书8', '17'); INSERT INTO `book` VALUES ('9', '图书9', '18'); INSERT INTO `book` VALUES ('10', '图书10', '19'); INSERT INTO `book` VALUES ('11', '图书11', '11'); INSERT INTO `book` VALUES ('12', '图书12', '23'); INSERT INTO `book` VALUES ('13', '图书13', '22'); INSERT INTO `book` VALUES ('14', '图书14', '22'); INSERT INTO `book` VALUES ('15', '图书15', '22'); INSERT INTO `book` VALUES ('16', '图书16', '9'); INSERT INTO `book` VALUES ('17', '图书17', '10'); INSERT INTO `book` VALUES ('18', '图书18', '2'); INSERT INTO `book` VALUES ('19', '图书19', '8'); INSERT INTO `book` VALUES ('20', '图书20', '78'); INSERT INTO `book` VALUES ('21', '图书21', '21'); INSERT INTO `book` VALUES ('22', '图书22', '22'); INSERT INTO `book` VALUES ('23', '图书23', '23'); INSERT INTO `book` VALUES ('24', '图书24', '24');

实例图

测试示例图

Bootstrap和Java分页实例第二篇

分页融合到自己的代码中示例图

Bootstrap和Java分页实例第二篇

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwjszf.html