在编写网页查询数据库时,需要把数据库中的数据显示出来,但是当数据库中的数据较多时,一页显示过多数据会使数据变得不够直观,所以一般需要进行分页设置。设置每页显示的数据的数量。
具体流程为:
1.导jar包
2.告诉mybatis要用pagehelper 添加到sqlsessionfactroy
3.在service层,在执行具体sql之前 PageHelper.startPage(page,size);
4.controler 把得到的list装到pageinfo里面
5,在页面展示
本次开发学习还是在之前的项目上进行迭代开发。
allUser页面进行了更改,具体代码如下:(table里面的,和下面的一个块)
<table id="dataList"
class="table table-bordered table-striped table-hover dataTable">
<thead>
<tr>
<th class="" style="padding-right: 0px"><input
id="selall" type="checkbox" class="icheckbox_square-blue">
</th>
<th class="sorting_asc">ID</th>
<th class="sorting_desc">用户名</th>
<th class="sorting_asc sorting_asc_disabled">密码</th>
<th class="text-center">操作</th>
</tr>
</thead>
<tbody>
<c:forEach var="user" items="${pageinfos.list}">
<tr>
<td><input name="ids" type="checkbox"></td>
<td>${user.id}</td>
<td>${user.username}</td>
<td>${user.password}</td>
<td class="text-center">
<a href="${pageContext.request.contextPath}/user/toUserupdate.do?id=${user.id}" class="btn bg-olive btn-xs">