springmvc、mybatis分页+pagehelper的使用(包括页面代码)

一、前台页面代码

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.8.3.js"></script>
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/css.css" type="text/css" />


<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>


<script type="text/javascript">
function jump_to(){
$("#userForm").attr("action","${pageContext.request.contextPath}/skipUser");
$("#userForm").submit();

}
function jump_update(id){
$("#userForm").attr("action","${pageContext.request.contextPath}/skipUser?userId="+id);
$("#userForm").submit();
}

function submitForm(id,value){
//1 为指定隐藏域赋值
$("#"+id).val(value)
$("#userForm").attr("action","${pageContext.request.contextPath}/userManager");
//2 提交表单
$("#userForm").submit();
}
function jump_delete(id,loginName){
if(confirm("您确定要删除"+loginName+"用户信息吗")){

$("#userForm").attr("action","${pageContext.request.contextPath}/deleteUser?userId="+id);
$("#userForm").submit();
}

}



</script>
</head>
<body leftmargin="0" topmargin="0" class="content_body">
<form  id="userForm" method="post" >
<!-- 当前页数 -->
<input type="hidden" name="currentPage" id="currentPage" value="${page.pagehelper.pageNum}"  />
<!-- 每页显示条数-->
<input type="hidden" name="pageSize" id="pageSize" value="${page.pagehelper.pageSize}" />
<center>
<table style="width: 96%">
<tr>
<td height="35">
<div align="left">
<img  src="${pageContext.request.contextPath }/images/I186.gif" width="16"
height="16" align="left">
<strong class="FontTitle">用户管理</strong>
</div>
</td>
</tr>

<tr>
<td height="2" bgcolor="#FF9933" width="100%"></td>
</tr>
</table>
<br>
<table class="table" width="96%" cellpadding="0" cellspacing="1" 
style="width: 95%;align:center;cellpadding:0;border:0px">
<tr class="record_even">
<td class="content_field_hr" align="center">
<strong>登录名</strong>
</td>
<td class="content_field_hr" align="center">
<strong>状态</strong>
</td>
<td class="content_field_hr" align="center">
<strong>角色</strong>
</td>
<td class="content_field_hr" align="center">
<strong>创建时间</strong>
</td>
<td class="content_field_hr" align="center">
<strong>描述</strong>
</td>
<td class="content_field_hr" align="center">
<strong>错误次数</strong>
</td>
<td class="content_field_hr" align="center">
<strong>操作</strong>
</td>
</tr>

<c:forEach var="user" items="#{page.list }"> 
<tr class="record_odd"
οnmοuseοver="this.style.backgroundColor='#C5DDED'"
οnmοuseοut="this.style.backgroundColor='#FBFBF0'">
<td align="center">
${user.loginName }
</td>
<td align="center">
${user.userStatus==1?"正常":"无效" }
</td>
<td align="center">
${user.roleName }
</td>
<td align="center">
${user.checkDtString }
</td>
<td align="center">
${user.comment }
</td>
<td align="center">
${user.errorTimes }
</td>
<td align="center">
<a href="javascript:jump_update('${user.userId }')">修改</a>&nbsp;
<a href="javascript:jump_delete('${user.userId  }','${user.loginName }')">删除</a>
</td>
</tr>
</c:forEach> 
</table>
<br>
<TR>
<TD><SPAN id=pagelink>
<DIV
style="LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: right ;padding-right: 40px ; ">
共[<B >${page.pagehelper.total}</B>]条记录,[<B>${page.pagehelper.pageNum}/${page.pagehelper.pages}</B>]页
,每页显示
<select id="pageSize_select" name="pageSize"  οnchange="submitForm('pageSize',$('#pageSize_select option:selected').val())" >
<option value="10" ${page.pagehelper.pageSize==10?'selected':''} >10</option>
<option value="20" ${page.pagehelper.pageSize==20?'selected':''} >20</option>
<option value="30" ${page.pagehelper.pageSize==30?'selected':''} >30</option>
</select>

<c:if test="${!page.pagehelper.isFirstPage}">
[<A href="javascript:void(0)" οnclick="submitForm('currentPage',${page.pagehelper.firstPage})" >首页</A>]
[<A href="javascript:void(0)" οnclick="submitForm('currentPage',${page.pagehelper.prePage})" >前一页</A>]
</c:if>
<B>${page.pagehelper.pageNum}</B>
<c:if test="${!page.pagehelper.isLastPage}">
[<A href="javascript:void(0)" οnclick="submitForm('currentPage',${page.pagehelper.nextPage})" >后一页</A>]
[<A href="javascript:void(0)" οnclick="submitForm('currentPage',${page.pagehelper.lastPage})" >末页</A>]
</c:if>

<input style="width: 10;height: 15px" type="text" size="3" id="page" name="page" value="${page.pagehelper.pageNum}" />
页;

<input type="button" value="Go" οnclick="submitForm('currentPage',$('#page').val())"/>
</DIV>
</SPAN></TD>
</TR>
<!-- 增加用户 -->
<table>
<tr>
<td align="center">
<input type="button" name="addUser" id="addUser" value="增加用户"
class="btnlarge" οnclick="jump_to();">
</td>
</tr>
</table>
</center>
</form>


</body>
</html>


二、后台代码

   1、controller层

//注入
@RequestMapping("/userManager")
public String userManager(Model model,
@RequestParam(defaultValue="1")Integer currentPage,
@RequestParam(defaultValue="20")Integer pageSize){

/*PageBean page = userService.findUserWithListPage(currentPage,pageSize);

model.addAttribute(ResponseWebContent.rap_User_Page_Model, page);*/

Map<String, Object> map = userService.findUserWithMap(currentPage,pageSize);
model.addAttribute(ResponseWebContent.rap_User_Page_Model, map);
return "/user/user_list2";
}


2、service层代码

/**
* 分页查询
* @param currentPage
* @param pageSize
* @return
* 2017年11月8日
*/
public Map<String, Object> findUserWithMap(Integer currentPage, Integer pageSize) {
PageHelper.startPage(currentPage, pageSize);
List<RapUser> list = rapUserMapper.selectAll();
PageInfo<RapUser> page = new PageInfo<>(list);

Map<String, Object> map = new  HashMap<>();
map.put("list", list);
map.put("pagehelper", page);
return map;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值