首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

iBATIS 分页处置

2012-10-28 
iBATIS 分页处理?ibatis分页实现主要步骤:a. 创建Page类。b.创建bean类,并继承Page类。b. 在dao层,定义两个

iBATIS 分页处理

?

ibatis分页实现主要步骤:

a. 创建Page类。
b.创建bean类,并继承Page类。
b. 在dao层,定义两个方法。并实现该方法。
c. 在业务层,同样定义两个方法。并实现它。
d. 在配置文件中注入有关的page类。并设置相应的get和set方法。
e. 在action中调用有关的方法。
f.进行配置文件的设置。

?


详细步骤
1.? ? ? ? Page类
package com.exeerp.sm.bean;
public class Page
{
? ? ? ? private int pagesize;//单页记录
? ? ? ? private int currentpage = 1;//当前页面
? ? ? ? private int countdate;//总记录数
? ? ? ? private int lastPage;
? ? ? ? private int nextPage;
? ? ? ? private int countPage;
? ? ? ? public int getCurrentpage()
? ? ? ? {
? ? ? ? ? ? ? ? return currentpage;
? ? ? ? }
? ? ? ? public void setCurrentpage(int currentpage)
? ? ? ? {
? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? if(currentpage>getCountpage())
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? this.currentpage = getCountpage();
? ? ? ? ? ? ? ? }else {
? ? ? ? ? ? ? ? ? ? ? ? if(currentpage < 1)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? this.currentpage = 1;
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? this.currentpage = currentpage;
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? }
? ? ? ? public int getPagesize() {
? ? ? ? ? ? ? ? return pagesize;
? ? ? ? }
? ? ? ? public void setPagesize(int pagesize) {
? ? ? ? ? ? ? ? this.pagesize = pagesize;
? ? ? ? }
? ? ? ? public int getCountdate()
? ? ? ? {
? ? ? ? ? ? ? ? return countdate;
? ? ? ? }
? ? ? ? public void setCountdate(int countdate)
? ? ? ? {
? ? ? ? ? ? ? ? this.countdate = countdate;
? ? ? ? }
? ? ? ? //由记录数设定有关的页面数。
? ? ? ? public int getCountpage()
? ? ? ? {
? ? ? ? ? ? ? ? int i = this.countdate / this.pagesize;
? ? ? ? ? ? ? ? if((this.countdate % this.pagesize)!=0)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? i+=1;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? return i;
? ? ? ? }
? ? ? ? public int getLastPage()
? ? ? ? {
? ? ? ? ? ? ? ? return this.getCurrentpage()-1;
? ? ? ? }
? ? ? ? public int getNextPage()
? ? ? ? {? ? ? ?
? ? ? ? ? ? ? ? return this.getCurrentpage()+1;
? ? ? ? }
? ? ? ? //给? ? ? ? ? ? ? ? <property name="flowManager" ref="flowManager"/>
? ? ? ? ? ? ? ? <property name="flow" ref="flow"/>
? ? ? ? ? ? ? ? <property name="page" ref="page"/>
? ? ? ? </bean>

Ibetis配置:
??<!-- 显示所有的审批信息 -->
??<select id="select-Flow" resultparameterresultcontentType="text/html;charset=GBK"%>
<%@page import="com.exeerp.sm.bean.Page"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ page import="java.util.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
? ? ? ? <head>
? ? ? ? ? ? ? ? <title>审批流程管理</title>
? ? ? ? ? ? ? ? <link href="css/style.css" rel="stylesheet"/>
<script language="JavaScript" type="text/javascript">

? ?? ???function choice(who)//全选和反选
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ?? ???var inputs=document.getElementsByName("check");
? ? ? ? ? ? ? ?? ???var selectedNum = 0;
? ? ? ? ? ? ? ?? ???for (var j=0;j<inputs.length;j++) //获取选中数量
? ? ? ? ? ? ? ?? ???{
? ? ? ? ? ? ? ?? ?? ?? ?if (inputs[j].checked == true) {selectedNum += 1;}
? ? ? ? ? ? ? ?? ???}
? ? ? ? ? ? ? ?? ???if (selectedNum = inputs.length) {who = 0;} //如果checkbox处于全部选中状态,则实现取消全选
? ? ? ? ? ? ? ?? ???if (who == 1) //全选
? ? ? ? ? ? ? ?? ???{
? ? ? ? ? ? ? ?? ?? ?? ?for (var i=0;i<inputs.length;i++)
? ? ? ? ? ? ? ?? ?? ?? ?{inputs.checked = true;}
? ? ? ? ? ? ? ?? ???}
? ? ? ? ? ? ? ?? ???else //反选
? ? ? ? ? ? ? ?? ???{
? ? ? ? ? ? ? ?? ?? ?? ?for (var i=0;i<inputs.length;i++)
? ? ? ? ? ? ? ?? ?? ?? ?{inputs.checked = !(inputs.checked);}? ?? ???
? ? ? ? ? ? ? ?? ???}
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? function panduan()//在删除删除进行选中的判定
? ? ? ? ? ? ? ? {? ? ? ? ? ? ? ?? ???
? ? ? ? ? ? ? ?? ???var cked = false;
? ? ? ? ? ? ? ?? ???var inputs=document.getElementsByName("check");
? ? ? ? ? ? ? ?? ???var selectedNum = 0;
? ? ? ? ? ? ? ?? ???for (var j=0;j<inputs.length;j++) //获取选中数量
? ? ? ? ? ? ? ?? ???{
? ? ? ? ? ? ? ?? ?? ?? ?if (inputs[j].checked == true)
? ? ? ? ? ? ? ?? ?? ?? ?{
? ? ? ? ? ? ? ?? ?? ?? ???selectedNum += 1;
? ? ? ? ? ? ? ?? ?? ?? ?}
? ? ? ? ? ? ? ?? ???}
? ? ? ?? ?? ?? ?if (selectedNum==0) {
? ? ? ? ? ? ? ?? ?? ?? ?alert("必须选择一个");
? ? ? ? ? ? ? ?? ?? ?? ?return false;
? ? ? ?? ?? ?? ?}else{
? ? ? ?? ?? ?? ?? ?if(confirm("您确定要删除"))
? ? ? ?? ?? ?? ?? ?{
? ? ? ?? ?? ?? ?? ???cked=true;
? ? ? ?? ?? ?? ?? ? return true;
? ? ? ?? ?? ?? ?? ?}else{
? ? ? ?? ?? ?? ?? ???return false;
? ? ? ?? ?? ?? ?? ?}
? ? ? ?? ?? ?? ???
? ? ? ? ? ? ? ?? ???}
? ? ? ?? ???}
? ? ? ?? ???function selOpenPage()//选择有关的页面数时,进行页面的跳转
? ?? ???{
? ?? ?? ?? ? var aa=document.getElementById("selpage").value;//获取选项的值
? ?? ?? ?? ? document.location.href="findAllAction-Flow.action?flow.currentpage="+aa; //转向查询所有的action并传递值? ?
? ?? ???}
</script>? ? ? ? </head>
? ? ? ? ? ? ? ?

? ? ? ? <body>
? ? ? ? <style>
??body{
? ? text-align:center;
??}

? ? ? ? .datatable{
? ? ? ? border:1px solid #d6dde6;
? ? ? ? border-collapse:collapse;
? ? ? ? }
? ? ? ? .datatable td{
? ? ? ? border:1px solid #d6dde6;
? ? ? ? text-align:right;
? ? ? ? padding:4px;
? ? ? ? }
? ? ? ?
? ? ? ? .datatable th{
? ? ? ? border:1px solid #828282;
? ? ? ?? ?? ?? ?? ?? ???background:#bcbcbc;
? ? ? ? font-weight:bold;
? ? ? ? text-align:left;
? ? ? ? padding:4px;
? ? ? ? }
? ? ? ? .datatable caption{
? ? ? ? font:bold 1.9em "Times New Roman",Times,serif;
? ? ? ? background:#b0c4de;
? ? ? ? color:333517;
? ? ? ? border:1px solid #78a367;
? ? ? ? }
? ? ? ?
? ? ? ? .datatable tr:hover, .datatable .highlight{
? ? ? ? background:#ffff00;
? ? ? ?
? ? ? ? }
? ? ? ? .altrow{
? ? ? ? background:#eefeef;
? ? ? ? color:#000000;
? ? ? ? }
</style>
? ? ? ? <%int i=1;%>
? ? ? ? 你好
? ? ? ? <h3><a href="flowadd.jsp">新增审批流程信息</a></h3>
? ? ? ? <a href="../sm_flowstep/findAllAction-Flowstep.action?flowstep.currentpage=1">进入审批环节管理主页</a>
? ? ? ? ? ? ? ? <a href="../sm_flowstepemp/findAllAction-Flowstepemp.action?flowstepemp.currentpage=1">进入审批环节处理管理主页</a>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <a href="../sm_coderule/findAllAction-Coderule.action?coderule.currentpage=1">进入编码规则管理主页</a>
<s:form theme="simple" action="./deleteAction-Flow.action" onsubmit="return panduan()">
<table>
<tr height="20px" bgcolor="red">
? ?<td>选择<br></td>
? ?<td>序号<br></td>
? ?<td>审批编号<br></td>
? ?<td>审批名称<br></td>
? ?<td>审批路径<br></td>
? ? <td>审批描述<br></td>
? ?<td>修改<br></td>
? ?<td>添加审批环节<br></td>
??</tr>
??<s:if test="#request.all==null">
? ? <tr>
? ?? ?<td>记录不存在!!!</td>
? ? </tr>
??</s:if>
? ?<s:iterator value="#request.all">
? ? ? ? ? ? ? ?? ? <tr onmouseover="this.style.backgroundColor='#cccccc'" onmouseout="this.style.backgroundColor=''">
? ? ? ? ? ? ? ? ? ? ? ???? ? ? ? ? ? ? ? ? ? ? ?? ? <td><s:checkbox name="check" id="check"??fieldValue="%{FLOWID}" > </s:checkbox> <br></td>
? ? ? ? ? ? ? ? ? ? ? ?? ???<td><%=i++%></td>
? ? ? ? ? ? ? ? ? ? ? ?? ? <td><s:property value="FLOWID"/></td>
? ? ? ? ? ? ? ? ? ? ? ?? ? <td><s:property value="FLOWNAME"/></td>
? ? ? ? ? ? ? ? ? ? ? ?? ???<td><s:property value="FLOWURL"/></td>
? ? ? ? ? ? ? ? ? ? ? ?? ?? ?<td><s:property value="FLOWCLASS"/></td>
? ? ? ? ? ? ? ? ? ? ? ?? ? <td><a href="findByIdAction-Flow.action?id=<s:property value="FLOWID"/>">修改</a><br></td>
? ? ? ? ? ? ? ?? ?? ???<td><a href="../sm_flowstep/flowstepadd.jsp?id=<s:property value="FLOWID"/>">添加审批环节</a><br></td>
? ? ? ? ? ? ? ?? ?</tr>
? ? ? ? </s:iterator>
? ? ? ?
? ?<tr><td><s:submit value="删除" onclick="return panduan()"/></td>
? ? <td><s:if test="#request.flow.currentpage>1"><a href="findAllAction-Flow.action?flow.currentpage=1">首??页</a></s:if>
? ? ? ? ? ? <s:if test="#request.flow.currentpage>1"><a href="findAllAction-Flow.action?flow.countpage=<s:property value="flow.lastPage"/>">上一页</a></s:if>
? ? ? ? ? ? <s:if test="#request.flow.countpage>1 && #request.flow.currentpage<#request.flow.countpage"><a href="findAllAction-Flow.action?flow.currentpage=<s:property value="flow.nextPage"/>">下一页</a></s:if>
? ? ? ? ? ? <s:if test="#request.flow.currentpage<#request.flow.countpage"><a href="findAllAction-Flow.action?flow.currentpage=<s:property value="flow.countpage"/>">尾??页</a></s:if>
? ? ? ? ? ? <s:property value="flow.currentpage"/>/<s:property value="flow.countpage"/>
? ? ? ? ? ? </td>
? ? ? ? ? ? <td width="80px">
? ? ? ? ? ? 共<s:property value='countdate'/>条数据</td>
? ? ? ? ? ? <%
? ? ? ? ? ?
? ? ? ? ? ? int maxPage=(Integer)request.getAttribute("flow.countpage");
? ? ? ? ? ? int cur=(Integer)request.getAttribute("flow.currentpage");
? ? ? ? ? ?
? ? ? ? ? ? %>
? ? ? ? ? ? <td>跳转到
? ? ? ? ? ? <select name="selpage" id="selpage" onChange="selOpenPage()">
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <%
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ???
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? for (int x = 1; x <= maxPage; x++) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? %>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <option value="<%=x%>"
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <%=cur== x ? "selected"
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? : ""%>><%=x%></option>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <%
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? %>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? </select>? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 页</td>
? ? ? ? ? ? <td><input type="button" value="全选/全不选"??onclick="choice(1)"/>|</td>
? ? ? ?? ???<td><input type="button" value="反 选"??onclick="choice(0)"/></td>
? ?</tr>
</table>
</s:form>
</body>
</html>
<script language="javascript">
onload=function(){
? ? var rows=document.getElementsByTagName("tr");
? ? for(var i=1;i<rows.length;i++)
? ? {
? ?? ???rows.index=i
? ?? ???rows.className=(i%2==0)?"":"altrow"
? ?? ???rows.onmouseover=function()
? ?? ???{
? ?? ?? ?? ?this.className="highlight";
? ?? ???}
? ?? ???rows.onmouseout=function()
? ?? ???{
? ?? ?? ?? ?this.className=this.index%2==0?"":"altrow";
? ?? ???}
? ? }
}
</script>

热点排行