标签通用分页详细注释

来源:互联网 发布:require.js兼容ie8吗 编辑:程序博客网 时间:2024/04/19 10:46

 1.1 将要查询的SQL放在一个ArrayList里面
    在业务包内的ip内 Ip_Function.java里面写如下函数
     /*----------------------------------------------------
         函数名称 :getB_infor_Table
         ----------------------------------------------------*/
        public PageResultSet getB_infor_Table(int curPage)//只要一个当前页参数
       {
           String sql="";
           DataBase_Operator m_db = new DataBase_Operator();
// DataBase_Operator包含了数据库连接,操作,获得值等功能。

         
               sql = "select id,Ip_Start,Ip_End,record_date,record_time,"
              + "reporter from IP";// ip表内的信息的查询语句
         
           Collection data = m_db.GetSQL_ArrayList(sql,null);//得到一个数据库操作信息集
          PageResultSet m_dataList = new PageResultSet(data, curPage, 10); //每页10条记录
           return m_dataList;//把结果返回以便set到页面
       }
   
1.2 分页接受参数和给jsp传递list数组和其他参数
    在业务包内的ip内 Ip_Action.java文件内
     // 以下查询结果需要分页显示:分以下两个步骤
      // 第一步:首次得到分页码
      int curPage = 1;//当前页默认为第一页
      if (servletRequest.getParameter("cur_page") == null) {
          curPage = 1;//如果没有获得当前页信息参数就把第一页作为当前页
      } else {
          curPage = Integer.parseInt(servletRequest.getParameter("cur_page"));
      }//如果有参数就按参数显示第几页
 
      //第二步:给页面传递信息
        ip_Form 信息
      servletRequest.setAttribute("ip_information",
                           ip_Form);//给页面传递信息
      PageResultSet pageResultSet = ip_function.getB_infor_Table(curPage);
//看要传的是第几页的信息
      ArrayList m_list = (ArrayList) pageResultSet.getData();//从数据库得到值
      ArrayList m_list_rs = new ArrayList();//把值传到页面

      if (m_list.size() == 0) {
} else {
          for (int i = 0; i < m_list.size(); i++) {
              //使用数组方式得到值
              String[] m_value = new String[6];
              m_value = (String[]) m_list.get(i);
              Ip_Form m_form = new Ip_Form();
              //设置隔行颜色差别
              if (i % 2 == 0) {
                  m_form.setLine_color(database.Constant.m_line_color1);
              } else {
                  m_form.setLine_color(database.Constant.m_line_color2);
             }
//form bean里如下
              m_form.setM_id(m_value[0]);
              m_form.setM_Ip_Start(m_value[1]);
              m_form.setM_Ip_End(m_value[2]);
              m_form.setM_record_date(m_value[3]);
              m_form.setM_record_time(m_value[4]);
              m_form.setM_reporter(m_value[5]);
              m_list_rs.add(m_form);
          }
      }
      servletRequest.setAttribute("list", m_list_rs);//往list里传值,给页面接收
      servletRequest.setAttribute("divpage_tools",
                           pageResultSet.getToolBar(
                                   "ip.do?p=ip_show"));//启动分页工具类
      return actionMapping.findForward("show");//跳转
    }

1.3 对应显示jsp文件里面 例如:ip.jsp
 
<%@ page contentType="text/html; charset=GB2312" %> <!—字符信息-->
<%@ include file="../comm/m_taglibs.jsp"%> <!—导入工具文件-->
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> <!—导入struts标签-->
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html:html>
<head>
<title>
</title>
</head>
<link href="../css/font.css" rel="stylesheet" type="text/css" >
<body bgcolor="#ffffff">
    <br><br>
   用户IP限定管理
    <br><br>
   <table width="95%">
  <tr>
     <td  align="right">
     <html:link page="/ip/ip.do?p=ip_add"> 增加 </html:link>
      </td>
  </tr>
</table>
<table width="95%"  border="1" cellpadding="4" cellspacing="1" bordercolor="steelblue" id="top" >
  <tr bgcolor="steelblue">
    <td align="center"><font color="white">序号</td>
    <td align="center"><font color="white">起始IP</td>
    <td align="center"><font color="white">终止IP</td>
    <td align="center"><font color="white">记录日期</td>
    <td align="center"><font color="white">记录时间</td>
    <td align="center"><font color="white">记录员</td>
    <td colspan="2" align="center"><font color="white">操作</td>
  </tr>
  <logic:iterate id="ip"  name="list"> <!—struts循环标签,list要与Action中的数组名对应-->
<tr bgcolor="<bean:write name="ip" property="line_color"/>">
        <td align="center" bgcolor="steelblue"> <!—设置行颜色-->
          <font color="white"><bean:write name="ip" property="m_id" /></font>
        </td>
      <td align="center"><bean:write name="ip" property="m_Ip_Start" /></td>
      <td align="center"><bean:write name="ip" property="m_Ip_End" /></td>
  <td align="center">
         <html:link page="/basic_set/basic_set.do?method=b_type_modify"
           paramId="id" paramName="rs"   paramProperty="m_id"> 修改</html:link>
      </td>

<html:link page="/manager_log/manager_log.do?method=view&academy_id=${rs.academy_id}"
           paramId="reporter"
           paramName="rs"
           paramProperty="reporter">
           共<font color="red"><bean:write name="rs" property="count" /></font>次
           </html:link>

      <td align="center"><bean:write name="ip" property="m_record_date" /></td>
      <td align="center"><bean:write name="ip" property="m_record_time" /></td>
      <td align="center"><bean:write name="ip" property="m_reporter" /></td>
      <td align="center">      <!—获得值-->
        <html:link page="/ip/ip.do?p=ip_modify" paramId="id" paramName="ip" paramProperty="m_id">修 改</html:link>
       </td>
        <td align="center">
        <html:link page="/ip/ip.do?p=ip_delete" paramId="id" paramName="ip" paramProperty="m_id">删 除</html:link>
        </td>
      </tr>
  </logic:iterate>
</table>
  <%=request.getAttribute("divpage_tools")%> <!—分页工具-->
</body>
</html:html>

特别需要注意的是:
配置文件的 scope="session" 如果其他无法传递值给第二页面

 <action input="/basic_set/b_infor.jsp" name="basic_Set_Form" parameter="method"
    path="/basic_set/basic_set" scope="session" type="basic_set.Basic_Set_Action">
      <display-name>基本设置表</display-name>
      <description>主要是一级数据字典的内容B_type and B_infor内容的增删改</description>
      <forward name="b_type" path="/basic_set/b_type.jsp" />
      <forward name="b_type_addmodify" path="/basic_set/b_type_addmodify.jsp" />
      <forward name="b_type_del" path="/basic_set/b_type_del.jsp" />

原创粉丝点击