• Struts2 + MySQL 实现分页


    代码结构:

    package com.action;
     
    import java.util.List;
    import java.util.Map;
     
    import com.bean.Pager;
    import com.bean.UserInfo;
    import com.dao.LendDao;
    import com.opensymphony.xwork2.ActionContext;
    import com.opensymphony.xwork2.ActionSupport;
    
     
    public class LendAction extends ActionSupport{
            private int pageNow=1;           //初始页为第一页
            private int pageSize=3;             //每页数据为4条,可调节
            
            public String execute() throws Exception{
                LendDao dao = new LendDao();
                
                List list = dao.selectLend(pageNow, pageSize);
                Pager page = new Pager(pageNow, dao.selectLendSize());
                
                Map session = ActionContext.getContext().getSession();
                session.put("userinfo", list);
                session.put("pageinfo", page);
                return SUCCESS;
            }
     
            public int getPageNow() {
                return pageNow;
            }
     
            public void setPageNow(int pageNow) {
                this.pageNow = pageNow;
            }
     
            public int getPageSize() {
                return pageSize;
            }
     
            public void setPageSize(int pageSize) {
                this.pageSize = pageSize;
            }
            
    }
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <%@taglib prefix="s" uri="/struts-tags"%>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <title>My JSP 'index.jsp' starting page</title>
      </head>
    <body>
        <table border="1" width="599">
            <tr>
                <td valign="top"><jsp:include page="lenduserinfo.jsp"></jsp:include></td>
            </tr>
        
            <tr bgcolor="#E9EDF5" class="font1">
                <td align="right">
                    <s:set name="page" value="#session.pageinfo"/>
                        <a href="lendaction?pageNow=1">首页</a>
                        
                        <s:if test="#page.hasPre">
                            <a href="lendaction?pageNow=<s:property value="#page.pageNow-1"/>">上一页</a>
                        </s:if>
                        <s:else>
                            <a href="lendaction?pageNow=1">上一页</a>
                        </s:else>
                        
                        <s:if test="#page.hasNext">
                            <a href="lendaction?pageNow=<s:property value="#page.pageNow+1"/>">下一页</a>
                        </s:if>
                        <s:else>
                            <a href="lendaction?pageNow=<s:property value="#page.totalPage"/>">下一页</a>
                        </s:else>
                        
                        <a href="lendaction?pageNow=<s:property value="#page.totalPage"/>">尾页</a>
                </td>
            </tr>
        </table>
      </body>
    
    </html>
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@taglib prefix="s" uri="/struts-tags"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <title>My JSP 'success.jsp' starting page</title>
      </head>
      
    <body>
        <table border="2">
            <tr>
                <td>userId</td>   
                <td>userName</td>        
                <td>userPassword</td>
            </tr>
               <s:iterator value="#session.userinfo" id="lend">
                   <tr>
                       <td><s:property value="#lend.userId" /></td>
                       <td><s:property value="#lend.userName" /></td>
                       <td><s:property value="#lend.userPassword" /></td>
                   </tr>
               </s:iterator>
        </table>
      </body>
    
    
    </html>
  • 相关阅读:
    Java Excel导入
    Git在Eclipse中忽略文件提交
    Git客户端安装(仅限windows用户)
    Java输出流文件下载
    Centos6.3源码安装Mysql-5.5.34
    Centos6.3安装Mongodb2.2.4
    Jacob操作Word各格式转换参数
    sublime text3使用小结
    获得select下拉框的值
    sublim text3 配置
  • 原文地址:https://www.cnblogs.com/Roni-i/p/9975731.html
Copyright © 2020-2023  润新知