jsp+mybatis+struts+spring+分页

xml文件 分页查询:
<select id="fenyeFind" resultMap="sBookResultMap" parameterType="int">
select * from sbook order by id
<if test="beginResult >= 0">
<if test="resultSize > 0">
limit #{beginResult},#{resultSize};
</if>
</if>
</select>


service的实现类:
public List<SBook> fenyeFind(Integer beginResult, Integer resultSize) {
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("beginResult", beginResult);
map.put("resultSize", resultSize);
return bookMapper.fenyeFind(map);
}

其中的bookMapper是一个接口。

分页action:
/**
* 分页的action
* @return success;
*/
public String fenyeShow() {
int count = bookServices.findAllBook().size();
int b = 1;
if(getBegin() > 0) {
b = getBegin();//设置当前行数
}
resultSize = 3;//每页显示的条数
total = count / resultSize + (count % resultSize == 0 ? 0 : 1);
for(int i = 1; i <= total; i ++) {
pages.add(i);//把总行数添加到集合中
}
ActionContext.getContext().put("pagesize", pages);//把集合放到上下文对象中
int a = (b - 1) * resultSize;//设置开始查询的数据
bookLst = bookServices.fenyeFind(a, resultSize);
return "success";
}


分页jsp1:
<%
//(int[])request.getAttribute("pagesize");
List<Integer> pa = (List<Integer>)ActionContext.getContext().get("pagesize");

for(int i = 1; i <= pa.size(); i ++) {
%>

<a href="<%=request.getContextPath()%>/sbook/fenye.action?begin=<%=i %>"><%=i %></a>
<%} %><br>

<br />
<jsp:include page="childFenye.jsp"></jsp:include>


分页jsp2:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<script type="text/javascript">
function gotoFenyeAction() {
var id = document.getElementById("fenyeForms");
id.submit();
}
</script>
<form action="<%=request.getContextPath()%>/sbook/fenye.action" method="post" id="fenyeForms">
<a href="<%=request.getContextPath()%>/sbook/fenye.action?begin=1">首页</a>
<c:if test="${begin>1}">
<a href="<%=request.getContextPath()%>/sbook/fenye.action?begin=${begin-1}">上一页</a>
</c:if>
跳转到第 <select name="begin" onchange="gotoFenyeAction();">
<c:forEach begin="1" end="${total}" step="1" var="pageIndex">
<c:choose>
<c:when test="${pageIndex eq begin}">
<option value="${pageIndex}" selected="selected">${pageIndex}</option>
</c:when>
<c:otherwise>
<option value="${pageIndex}">${pageIndex}</option>
</c:otherwise>
</c:choose>
</c:forEach>
</select>页
<c:choose>
<c:when test="${begin == null || begin == 0 }">
<a href="<%=request.getContextPath()%>/sbook/fenye.action?begin=${begin + 2}">下一页</a>
</c:when>
<c:when test="${begin < total }">
<a href="<%=request.getContextPath()%>/sbook/fenye.action?begin=${begin + 1}">下一页</a>
</c:when>
</c:choose>
</c:if>
<a href="<%=request.getContextPath()%>/sbook/fenye.action?begin=${total}">末页</a>
</form>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值