前段代码:
<div align="center">
<div id="div11" align="center">
<c:choose>
<c:when test="${alluser eq null or fn:length(alluser)==0}">
<font>不存在用户</font>
</c:when>
<c:otherwise>
<table align="center" border="1px soild red" cellpadding="0" cellspacing="0">
<tr>
<td>编号</td>
<td>姓名</td>
<td>密码</td>
<td>生日</td>
<td>地点</td>
<c:forEach var="item" items="${alluser}">
<tr>
<td>${item.id}</td>
<td>${item.uname}</td>
<td>${item.upass}</td>
<td><fmt:formatDate value="${item.ubirth}" pattern="yyyy-MM-dd"/> </td>
<td>${item.place}</td>
</tr>
</c:forEach>
</tr>
</table>
</c:otherwise>
</c:choose>
</div>
<div align="center" id="div12">
<script type="text/javascript">
for (var i=1;i<=${buttonnum};i++){
document.write("<button class='btn' value="+i+" οnclick="+"javascript:functiononclick("+i+");>"+i+"</button> ")
}
function functiononclick(id) {
location.href="buttonid?id="+id;
}
</script>
</div>
</div>
java后台代码
try {
//前段请求id
Integer integer = new Integer(id);
//每个页面的数据
int sizes=4;
//每个页面数据开始的位置
int num=((integer-1)*sizes);
//计算显示多少个请求按钮
int buttonnum=0;
//获取数据条数
Integer selectusercounts = userService.selectusercounts();
if(selectusercounts%sizes==0){
buttonnum=selectusercounts/sizes;
}else {
buttonnum=selectusercounts/sizes+1;
}
//按条件查询数据
List<Users> users = userService.selectuserfenye(num, sizes);
//保存数据到modelAndView
modelAndView.addObject("alluser",users);
modelAndView.addObject("buttonnum",buttonnum);
//System.out.println(users.toString());
//跳转的目的界面
modelAndView.setViewName("fenteusers");
} catch (Exception e) {
e.printStackTrace();
}
数据库:
<!--查询用户数据条数-->
<select id="selectusercounts" resultType="integer">
select count(*) from users;
</select>
<!--查询用户数据条数-->
<select id="selectuserfenye" resultType="com.example.orm.Users">
SELECT * from users LIMIT #{num},#{sizes};
</select>
来源:CSDN
作者:weixin_45380978
链接:https://blog.csdn.net/weixin_45380978/article/details/104340102