利用xml数据导实现分页

<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="org.apache.struts.util.LabelValueBean"%>
<%@ page import="java.util.List"%>
<%@ taglib uri="struts-bean" prefix="bean"%>
<%@ taglib uri="struts-html" prefix="html"%>
<%@ taglib uri="struts-logic" prefix="logic"%>
<%@ page import="com.neusoft.schoolcard.dao.sysmanager.PersonVO"%>
<%@ page import="com.neusoft.schoolcard.bo.CardUserManagerBO"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
 
<xml id="xmlPersons">
    <personList>     
     <logic:iterate id="tmp" name="vo" scope="request"><!-- vo是个ArrayList里面存放的是PersonVO -->
     <part>
     <accounthref><%=path%>/CardUserManagerAction.do?method=updatePerson&amp;operate=<bean:write name="tmp" property="account"/></accounthref>
     <account><bean:write name="tmp" property="account"/></account>
     <name><bean:write name="tmp" property="name"/></name>
     <sex><logic:equal name="tmp" property="sex" value="11">男</logic:equal><logic:equal name="tmp" property="sex" value="12">女</logic:equal></sex>
     <bankAcc><bean:write name="tmp" property="bankAcc"/></bankAcc>
     <studentId><bean:write name="tmp" property="studentId"/></studentId>     
     <identityName><logic:notEqual name="tmp" property="idenNO" value="0"><bean:write name="tmp" property="identityName"/></logic:notEqual></identityName>
     <academyName><bean:write name="tmp" property="academyName"/></academyName>
     <departmentName><bean:write name="tmp" property="departmantName"/></departmentName>
     <className><bean:write name="tmp" property="className"/></className>
     <grade><bean:write name="tmp" property="grade"/></grade>
     </part>
     </logic:iterate>
    </personList>
 </xml>
<html:html>
<head>
 <base href="<%=basePath%>">

 <title>查询列表</title>

 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">

 <link rel="stylesheet" type="text/css" href="<%=path%>/css/common6.css">
 <SCRIPT language='javascript'>
     function onQuery()
     {
      if(document.all.studentId.value.length!=0)
      {
       if(/[^0-9]+/.test(document.all.studentId.value)==true)
       {
        alert("学/工号请输入数字!");
        return false;
       }
      }
      document.all.method.value = "doQuery"; 
      document.CardUserManagerForm.submit();  
     }
     function createPerson()
     {
      document.all.method.value = "createPerson";
      open('<%= path%>/CardUserManagerAction.do?method=createPerson','_blank');
     }
     function onReset()
     {
      if(typeof(document.all.personRadio)=="undefined")
      {
       alert("表中无记录,无法进行该操作!");
       return false;
      }
      var radioCheck=document.all.personRadio;
         var result=false;
         var back=false;
         var rst="length" in document.all.personRadio; 
       
         if(!rst)
         {           
             if(radioCheck.checked==true)            
             {
                 result=true;
                 back=window.confirm("确定要将此项密码重置么?");
               
                 if(back==true)
                 {
                     document.all.method.value="doReset";
                     document.all.operate.value=radioCheck.value;
                     document.CardUserManagerForm.submit();
                 }
              }
         }
         else
         {
             for(var i=0;i<radioCheck.length;i++)
             {
                 if(radioCheck[i].checked==true)            
                 {
                     result=true;
                     back=window.confirm("确定要将此项密码重置么?");
               
                     if(back==true)
                     {
                         document.all.method.value="doReset";
                         document.all.operate.value=radioCheck[i].value;
                         document.CardUserManagerForm.submit();
                     }
                 }
              }
          }       
          if(result==false)
           alert("请选择一项!");     
     }
     删除
     function deletePerson()
     {
      if(typeof(document.all.personRadio)=="undefined")
      {
       alert("表中无记录,无法进行该操作!");
       return false;
      }
      var radioCheck=document.all.personRadio;
         var result=false;
         var back=false;
         var rst="length" in document.all.personRadio; 
       
         if(!rst)
         {           
             if(radioCheck.checked==true)            
             {
                 result=true;
                 back=window.confirm("确定要删除此项么?");
               
                 if(back==true)
                 {
                     document.all.method.value="doDelete";
                     document.all.operate.value=radioCheck.value;
                     document.CardUserManagerForm.submit();
                 }
              }
         }
         else
         {
             for(var i=0;i<radioCheck.length;i++)
             {
                 if(radioCheck[i].checked==true)            
                 {
                     result=true;
                     back=window.confirm("确定要删除此项么?");
               
                     if(back==true)
                     {
                         document.all.method.value="doDelete";
                         document.all.operate.value=radioCheck[i].value;
                         document.CardUserManagerForm.submit();
                     }
                 }
              }
          }       
          if(result==false)
           alert("请选择一项!");     
     }
     function updatePerson()
     {
      if(typeof(document.all.personRadio)=="undefined")
      {
       alert("表中无记录,无法进行该操作!");
       return false;
      }
      var radioCheck=document.all.personRadio;
         var result=false;
         var back=false;
         var rst="length" in document.all.personRadio; 
       
         if(!rst)
         {           
             if(radioCheck.checked==true)            
             {
                 result=true;
                 back=window.confirm("确定要修改此项么?");
               
                 if(back==true)
                 {
                  document.all.method.value = "updatePerson";
                     window.open("<%= path%>/CardUserManagerAction.do?method=updatePerson&operate="+radioCheck.value,"_blank");                                         
                 }
              }
         }
         else
         {
             for(var i=0;i<radioCheck.length;i++)
             {
                 if(radioCheck[i].checked==true)            
                 {
                     result=true;
                     back=window.confirm("确定要修改此项么?");
               
                     if(back==true)
                     {
                         document.all.method.value = "updatePerson";
                      window.open("<%= path%>/CardUserManagerAction.do?method=updatePerson&operate="+radioCheck[i].value,"_blank");     
                     }
                 }
              }
          }       
          if(result==false)
           alert("请选择一项!");     
     }
     
     function onChangeAcademy()
     {
      document.all.method.value = "doSelectAcademy";      
      document.CardUserManagerForm.submit();      
     }
     function onChangeDepartment()
     {
      document.all.method.value = "doSelectDepartment";
      document.CardUserManagerForm.submit();
     }
     //上一页
     function perPage()
     {
      var thisPage = document.all.thisPage2.value;
      document.all.next.disabled=false;
      document.all.next.className = "NextPageBTN";
      document.all.last.disabled=false;
      document.all.last.className = "LastPageBTN";
      if((parseInt(thisPage))==2)
      {
       document.all.per.disabled=true;
       document.all.per.className = "PrePageBTN1";
       document.all.first.disabled=true;
       document.all.first.className = "FirstPageBTN1";
      }
      if((parseInt(thisPage))>1)
      {
       thisPage1.innerHTML=--thisPage;
       document.all.thisPage2.value=thisPage;
      }
      for(var i = 0;i < document.CardUserManagerForm.personRadio.length;i++)
      {
       document.CardUserManagerForm.personRadio[i].checked=false;
      }
      table2.previousPage();
     }
     //下一页
     function nextPage()
     {
      var thisPage=document.all.thisPage2.value;
      var pageAll=document.all.pageAll.value;
      document.all.per.disabled=false;
      document.all.per.className = "PrePageBTN";
      document.all.first.disabled=false;
      document.all.first.className = "FirstPageBTN";
      if((parseInt(thisPage))==(parseInt(pageAll)-1))
      {
          document.all.next.disabled=true;
          document.all.next.className = "NextPageBTN1";
          document.all.last.disabled=true;
          document.all.last.className = "LastPageBTN1";
      }
      if((parseInt(thisPage))<(parseInt(pageAll)))
      {
         thisPage1.innerHTML=++thisPage;
       document.all.thisPage2.value=thisPage;
      }    
      for(var i = 0;i < document.CardUserManagerForm.personRadio.length;i++)
      {
       document.CardUserManagerForm.personRadio[i].checked=false;
      }
      table2.nextPage();
     }
     
     <!--跳转到某一页-->
    function jump()
    {
        document.all.per.disabled=false;
        document.all.per.className = "PrePageBTN";
        document.all.next.disabled=false;
        document.all.next.className = "NextPageBTN";
        document.all.first.disabled=false;
        document.all.first.className = "FirstPageBTN";
        document.all.last.disabled=false;
        document.all.last.className = "LastPageBTN";
        pageNum=document.all.page.value;
        pageAll=document.all.pageAll.value;
             
        if((parseInt(pageNum))>(parseInt(pageAll))||(parseInt(pageNum)<=0))
        {
            alert("请输入正确的页数!");
            document.all.page.value="";         
            document.all.page.focus();
        }      
        else if(pageNum=="")
        {
            alert("请输入页数!");
            document.all.page.focus();
        }      
        else if((parseInt(pageNum))<=(parseInt(pageAll)))
        {
            table2.firstPage();
            for(var i=1; i<pageNum; i++)
            {
                table2.nextPage();
            }
            if(parseInt(pageNum)==1)
            {
                document.all.per.disabled=true;
                document.all.per.className = "PrePageBTN1";
                document.all.first.disabled=true;
                document.all.first.className = "FirstPageBTN1";
            }
            if(parseInt(pageNum)==(parseInt(pageAll)))
            {
                document.all.next.disabled=true;
                document.all.next.className = "NextPageBTN1";
                document.all.last.disabled=true;
                document.all.last.className = "LastPageBTN1";
            }

            thisPage1.innerHTML = pageNum;
            document.all.thisPage2.value=pageNum;
            document.all.page.value="";
        }       
        else
        {
            alert("输入页数不符合规范!");
            document.all.page.value="";           
            document.all.page.focus();
        }      
    }
    /首页
     function firstPage()
     {
      document.all.per.disabled=true;
      document.all.per.className = "PrePageBTN1";
      document.all.first.disabled=true;
      document.all.first.className = "FirstPageBTN1";
      document.all.next.disabled=false;
      document.all.next.className = "NextPageBTN";
      document.all.last.disabled=false;
      document.all.last.className = "LastPageBTN";
      thisPage1.innerHTML=1;
      document.all.thisPage2.value=1;
      table2.firstPage();
     }
     /尾页
     function lastPage()
     {
      document.all.per.disabled=false;
      document.all.per.className = "PrePageBTN";
      document.all.first.disabled=false;
      document.all.first.className = "FirstPageBTN";
      document.all.next.disabled=true;
      document.all.next.className = "NextPageBTN1";
      document.all.last.disabled=true;
      document.all.last.className = "LastPageBTN1";
      thisPage1.innerHTML=document.all.pageAll.value;
      document.all.thisPage2.value=document.all.pageAll.value;
      table2.lastPage()
     }
     <!--第一次进入页面,判断"前一页"和"后一页"按钮是否为disabled-->
     function init()
     {
         document.all.per.disabled=true;
         document.all.per.className = "PrePageBTN1";
         document.all.first.disabled=true;
         document.all.first.className = "FirstPageBTN1";
       
         var thisPage=document.all.thisPage2.value;
      var pageAll=document.all.pageAll.value;
      if((parseInt(thisPage))==(parseInt(pageAll)))
      {
          document.all.next.disabled=true;
          document.all.next.className = "NextPageBTN1";
          document.all.last.disabled=true;
          document.all.last.className = "LastPageBTN1";
          document.all.go.disabled=true;
            }
            if(<%=(request.getAttribute("doSuccess")!=null)%>)
            {
             alert("<%=request.getAttribute("doSuccess")%>");
             <%request.removeAttribute("doSuccess");%>
            }
            else if(<%=request.getAttribute("doFail")!=null%>)
            {
             alert("<%=request.getAttribute("doFail")%>");
             <%request.removeAttribute("doFail");%>
            }
     }
     
    </SCRIPT>
</head>

<body οnlοad="init()">
 <!-- 计算分页 -->
<%List personList = (List)request.getAttribute("vo");
  int listMax = personList.size();
  int rowsPerPage =10;
  int pageMax=1;
  if(listMax!=0)
  {
      if(listMax%rowsPerPage == 0)
      {
          pageMax = listMax/rowsPerPage;
      }
      else
      {
          pageMax = listMax/rowsPerPage+1;
      }
  }
  %>

 <html:form action='/CardUserManagerAction.do' method="post">
   <TABLE align="center"  class="ReadOnly" width="100%" cellspacing=0>
    <TR class="TrEven">
     <TD width="25%">学院:<html:select property="academy" οnchange="onChangeAcademy()">
   <html:options collection="academys" property="value" labelProperty="label" />
  </html:select>
     </TD>
     <TD width="25%">系 &nbsp;:<html:select property="department" οnchange="onChangeDepartment()">
         <html:options collection="departments" property="value" labelProperty="label" />
       </html:select>
     </TD>
     <TD width="25%">班级:<html:select property = 'classno'>
       <html:options collection="classs" property="value" labelProperty="label" />
       </html:select>
     </TD>
     <TD width="25%">年级:<html:select property = 'grade'>
       <html:options collection="grades" property="value" labelProperty="label" />
       </html:select>
     </TD>
     <TD width=10>&nbsp;</TD>
    </TR>
    <TR class="TrEven">
     <TD>性别:<html:select property = 'sex'>
       <html:options collection="sexs" property="value" labelProperty="label" />
       </html:select>
     </TD>
     <TD>身份:<html:select property = 'identity'>
       <html:options collection="identitys" property="value" labelProperty="label" />
       </html:select>
     </TD>
     <TD colspan=3>民族:<html:select property = 'nation'>
       <html:options collection="nations" property="value" labelProperty="label" />
       </html:select>
     </TD>
    </TR>
    <TR class="TrEven">
     <TD>学/工号:<html:text property = 'studentId' />
     </td>
     <TD colspan=3>    姓名:<html:text property = 'name1' />
     </TD>
     <TD><html:button styleClass="BTN" property = 'query' value = '查询' onclick = 'onQuery()'/>
     </TD>
    </TR>
   </TABLE>     
   <HR width = '100%' size = 2>
   <TABLE id = 'table2' NAME = 'table2' datasrc="#xmlPersons" datapagesize="<%=rowsPerPage%>"  width="100%" align="center" border="black" bordercolor="black"  style="background-color:#FFFFFF;border-color:black;border-collapse:collapse;">
  <thead class="TrEven">
  <tr>
           <td colspan="12" height="23">
           <table  class="TdNewSubHead" height="21" width="100%" >
           <tr>
             <td align="center">
             <font color="white" size="3">  <b>个人信息维护</b><font>
             </td>
            </tr>
          </table>
        </td>
    </tr>
    <tr align="center"  class="TdNewSubHead">
   <td> &nbsp;&nbsp;
   </td>
   <td>IC卡号
   </td>
   <td>姓名
   </td>
   <td>性别
   </td>
   <td>银行卡号
   </td>
   <td>学/工号
   </td>
   <td>身份
   </td>
   <td>学院
   </td>
   <td>&nbsp;系&nbsp;
   </td>
   <td>班级
   </td>
   <td>年级
   </td>
 </tr>
 </thead>
 <tr>
  <td colspan=11 align="center">
  <logic:notPresent name="vo">
   没有您要查询的信息!
  </logic:notPresent>
  <logic:present name="vo">
   <logic:empty name="vo">
    没有您要查询的信息!
   </logic:empty>
  </logic:present>
  </td>
 </tr>
 <tr class="TrOdd" align="center">
 <logic:present name="vo">
        <logic:notEmpty name="vo">
            <td width="4%">
                <input style="cursor:hand" type="radio" name="personRadio" οnclick="this.value=this.nextSibling.nextSibling.value">
                <input type="hidden" datafld="account">
            </td>
      <td><a style="cursor:hand" target = '_blank' datafld="accounthref"><div datafld="account"/></a></td>
         <td><div datafld="name"/></td>
            <td><div datafld="sex"/></td>
            <td><div datafld="bankAcc"/></td>
            <td><div datafld="studentId"/></td>
            <td><div datafld="identityName"/></td>
            <td><div datafld="academyName"/></td>
            <td><div datafld="departmentName"/></td>
            <td><div datafld="className"/></td>
            <td><div datafld="grade"/></td> 
        </logic:notEmpty>
    </logic:present>
    </tr>

 <TFOOT>
 <tr class="TdNewSubHead">  
  <td align="left" colspan="11" >
   <input class="BTN" type = 'button' name = 'create' value = '新增' onclick = 'createPerson()'/>
     <input class="BTN" type = 'button' name = 'deletep' value = '删除' onclick = 'deletePerson()'/>
     <input class="BTN" type = 'button' name = 'update' value = '修改' onclick = 'updatePerson()'/>
      <input class="BTN" type = 'button' name = 'resetPassword' value = '密码重置' onclick = 'onReset()'/>
       <html:hidden  property="operate"/>  
       &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 共 <%=pageMax%> 页&nbsp;&nbsp; 每页 <%=rowsPerPage%> 条&nbsp;
   <input class="FirstPageBTN" type='button' name='first' id='first' value="" οnclick="firstPage()">
   <input type="button" class="PrePageBTN" id="per" value="" οnclick="perPage()"/>
   <span id="thisPage1">1</span>/<span><%= pageMax%></span>
   <input type="button" class="NextPageBTN" id="next" value="" οnclick="nextPage()"/>
   <input class="LastPageBTN" type='button' name='last' id='last' value="" οnclick="lastPage()">
   &nbsp;第 <input type="text" name="page" size="2" class="TdInput"> 页
   <input class="BTN" type="button" name="go" value="跳转" οnclick="jump()">                  
            <input class="BTN" type="hidden" name="pageAll" value="<%=pageMax%>">
            <input class="BTN" type="hidden" name="thisPage2" value="1">
  </td>
 </tr>
 </TFOOT>
   </TABLE> 
   <html:hidden property='method'/>
 </html:form>
</body>
</html:html> 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
PageHelper是一个优秀的分页插件,可以快速实现分页功能。而PageInfo是PageHelper中用于封装分页信息的类,可以方便地获取分页相关的信息,比如当前页码、总页数、总记录数等。下面是一个基于PageHelper和PageInfo实现分页的示例代码: 1. 首先,在pom.xml中添加PageHelper依赖: ```xml <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.2.1</version> </dependency> ``` 2. 在需要进行分页的Mapper方法中添加分页参数: ```java public interface UserMapper { List<User> selectAllUsers(); List<User> selectUsersByPage(@Param("start") int start, @Param("pageSize") int pageSize); } ``` 3. 在DAO层中进行分页操作: ```java @Service public class UserServiceImpl implements UserService { @Autowired private UserMapper userMapper; @Override public PageInfo<User> getUsersByPage(int pageNum, int pageSize) { PageHelper.startPage(pageNum, pageSize); List<User> userList = userMapper.selectAllUsers(); return new PageInfo<>(userList); } } ``` 4. 在Controller中获取分页数据: ```java @RestController @RequestMapping("/users") public class UserController { @Autowired private UserService userService; @GetMapping public PageInfo<User> getUsersByPage(@RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int pageSize) { return userService.getUsersByPage(pageNum, pageSize); } } ``` 5. 在前端页面中使用PageInfo组件进行分页: ```html <ul> <li v-for="user in userList" :key="user.id">{{ user.name }}</li> </ul> <PageInfo :page-info="pageInfo" @page-change="handlePageChange" /> ``` ```js import PageInfo from 'vue-pageinfo' export default { components: { PageInfo }, data() { return { userList: [], // 当前页的用户列表 pageInfo: null // 分页信息 } }, mounted() { this.getUserList() }, methods: { getUserList() { axios.get('/users', { params: { pageNum: this.pageInfo ? this.pageInfo.pageNum : 1, pageSize: this.pageInfo ? this.pageInfo.pageSize : 10 } }).then(response => { this.userList = response.data.list this.pageInfo = response.data }) }, handlePageChange(page) { // 处理页码改变事件 this.pageInfo.pageNum = page this.getUserList() } } } ``` 希望这个示例能够帮助到您!
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值