bootstrap是什么? Bootstrap是Twitter推出的一个用于前端开发的开源工具包。它由Twitter的设计师Mark Otto和Jacob Thornton合作开发,是一个CSS/HTML框架
(1)复制bootstrap的内容到webapp文件夹 (2)在页面引入 (3)使用项目访问路径 ${path} (4)设置spring-mvc的静态资源拦截规则 (5)测试
1.3个meta标签必须放在最前面,任何其他内容都必须跟随其后 2.jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery,所以必须放在前边)
<head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! --> <%pageContext.setAttribute("path",request.getContextPath());%> <%--上述 拿到项目地址--%> <link href="${path}/css/bootstrap.min.css" rel="stylesheet"> <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery,所以必须放在前边) --> <script src="${path}/js/jquery-1.11.0.min.js"></script> <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 --> <script src="${path}/js/bootstrap.min.js"></script> <title>Title</title> </head>然后在bootstrap的官网上搬运css样式 https://v3.bootcss.com/css/
创建pageBean 四个参数 总条数 总页数 每页条数 当前第几页 一个集合(四个整数的数据)
总条数(total): select count(*) from company 每页条数(pagesize):自己定 总页数: total%pagesize==0?total/pagesize:total/pagesize+1 当前几页(currentpage) 集合list:start ,pagesize start:(currentpage-1)*pagesize limit start ,pagesize 分页 select * from company where limit start ,pagesize(当前页的数据是在数据库中start行开始,到start+pagesize行结束)
pagehelper是什么? 针对Mybatis提供分页插件,将分页查询简化
(1)依赖配置 pagehelper (2)配置插件plugin 》1 : mybatis核心配置文件,在application中引入 mybatis核心配置文件 》2 : 直接在application中配置
注意还需要在applicationContext.xml中添加 在session工厂中加入
<property name="configLocation" value="classpath:SqlMapConfig.xml"/>也就是
<!-- session工厂--> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <!-- com.wzx.domain.Person person--> <property name="typeAliasesPackage" value="com.wzx.domain"/> <property name="configLocation" value="classpath:SqlMapConfig.xml"/> </bean>在session工厂中加入
<!-- PageHelper配置 --> <property name="plugins"> <array> <bean class="com.github.pagehelper.PageInterceptor"> <property name="properties"> <!--使用下面的方式配置参数,一行配置一个 --> <!-- pageNum<=0 时会查询第一页 --> <!-- 指定数据库方言 --> <value> reasonable=true helperDialect=mysql </value> </property> </bean> </array> </property>也就是
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <!-- com.wzx.domain.Person person--> <property name="typeAliasesPackage" value="com.wzx.domain"/> <!-- <property name="configLocation" value="classpath:SqlMapConfig.xml"/>--> <!-- PageHelper配置 --> <property name="plugins"> <array> <bean class="com.github.pagehelper.PageInterceptor"> <property name="properties"> <!--使用下面的方式配置参数,一行配置一个 --> <!-- pageNum<=0 时会查询第一页 --> <!-- 指定数据库方言 --> <value> reasonable=true helperDialect=mysql </value> </property> </bean> </array> </property> </bean>由于拦截器PageInterceptor会拦截sql语句,所以只要写一个全查语句,拦截器会自动拼接limit分页
select count(*) from department select * from department limit 0, 20 ;//第一页 select * from department limit 20, 20 ;//第二页 select * from department;//由拦截器 PageInterceptor生成以上sql先调用PageHelper.start(1,10)再调用全查,才能自动分页
sql查询语句不能加";"分号
<select id="findAllDepartment" resultType="department"> select * from department </select>》》导入c标签 使用里面的foreach与if标签 <%@ taglib prefix=“c” uri=“http://java.sun.com/jsp/jstl/core” %> 》》循环列表的行
<%-- Created by IntelliJ IDEA. User: 25863 Date: 2020/10/22 Time: 10:31 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" isELIgnored="false" language="java" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! --> <% pageContext.setAttribute("path",request.getContextPath());%> <%--上述 拿到项目地址--%> <link href="${path}/css/bootstrap.min.css" rel="stylesheet"> <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery,所以必须放在前边) --> <script src="${path}/js/jquery-1.11.0.min.js"></script> <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 --> <script src="${path}/js/bootstrap.min.js"></script> <title>Title</title> </head> <body> ${pi} <div class="container" > <!-- container 表示容器,所有内容放进这个容器--> <div class="row"> <!-- row表示 一行的宽度--> <div class="col-md-4" > <!--col-md-4 表示使用一行的4/12宽度 --> <h1>部门列表</h1> </div> </div> <div class="row"> <%-- <div class="col-md-8" ></div>--%> <div class="col-md-4 col-md-offset-8" > <button class="btn btn-primary"> <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> 新增</button> </div> </div> <div class="row"> <div class="col-md-12" > <table class="table table-hover"> <tr > <th >部门编号</th> <th ></th> <th >部门名称</th> <th >操作</th> </tr> <c:forEach items="${pi.list}" var="dept"> <!--将一行循环指定的次数 --> <tr> <td>${dept.did}</td> <td></td> <td>${dept.dname}</td> <td> <button class="btn btn-danger"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span> 删除 </button> <button class="btn btn-info"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> 修改 </button> </td> </tr> </c:forEach> </table> </div> </div> <div class="row"> <div class="col-md-6" >当前共有${pi.total}条记录,共${pi.pages}页</div> <div class="col-md-6" > <nav aria-label="Page navigation"> <ul class="pagination"> <li> <a href="#" aria-label="Previous"> <span aria-hidden="true">首页</span> </a> </li> <c:if test="${pi.hasPreviousPage}"> <li> <a href="#" aria-label="Previous"> <span aria-hidden="true">上一页</span> </a> </li> </c:if> <%-- <li class="active"><a href="#">1</a></li>--%> <c:forEach items="${pi.navigatepageNums}" var="num"> <c:if test="${num == pi.pageNum}"> <li class="active"><a href="#">${num}</a></li> </c:if> <c:if test="${num != pi.pageNum}"> <li><a href="#">${num}</a></li> </c:if> </c:forEach> <c:if test="${pi.hasNextPage}"> <li> <a href="#" aria-label="Next"> <span aria-hidden="true">下一页</span> </a> </li> </c:if> <li> <a href="#" aria-label="Previous"> <span aria-hidden="true">末页</span> </a> </li> </ul> </nav> </div> </div> </div> </body> </html>