基于Javaweb实现ATM机系统开发实战(十四)交易记录分页实现

news2024/12/23 6:42:54

还是老规矩,先看前端页面查看需要传递哪些参数,并且把逻辑有问题的部分进行修改~

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%> 
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>IMUT_BANK ATM WelCome!!</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <!-- Le styles -->
    <script type="text/javascript" src="assets/js/jquery.min.js"></script>

    <link rel="stylesheet" href="assets/css/style.css">
    <link rel="stylesheet" href="assets/css/loader-style.css">
    <link rel="stylesheet" href="assets/css/bootstrap.css">

    <link href="assets/css/icons-style.css" rel="stylesheet">
    <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
        <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
    <!-- Fav and touch icons -->
    <link rel="shortcut icon" href="assets/ico/minus.png">
<!--     <style type="text/css">
		a{
			color: blue;
		}
		a: hover {
			color: Red;
		}
	</style> -->
</head>

<body>
    <!-- Preloader -->
    <div id="preloader">
        <div id="status">&nbsp;</div>
    </div>
    <!-- TOP NAVBAR -->
    <nav role="navigation" class="navbar navbar-static-top">
        <div class="container-fluid">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button data-target="#bs-example-navbar-collapse-1" data-toggle="collapse" class="navbar-toggle" type="button">
                    <span class="entypo-menu"></span>
                </button>
                <button class="navbar-toggle toggle-menu-mobile toggle-left" type="button">
                    <span class="entypo-list-add"></span>
                </button>




                <div id="logo-mobile" class="visible-xs">
                   <h1>IMUT ATM<span>v2.2.7</span></h1>
                </div>

            </div>


            <!-- Collect the nav links, forms, and other content for toggling -->
            <div id="bs-example-navbar-collapse-1" class="collapse navbar-collapse">
                <ul class="nav navbar-nav">

                    <li class="dropdown">

                       
                        <ul style="margin: 11px 0 0 9px;" role="menu" class="dropdown-menu dropdown-wrap">
                            
                          
                        </ul>
                    </li>
                    
                    <li><a href="#"><i data-toggle="tooltip" data-placement="bottom" title="Help" style="font-size:20px;" class="icon-help tooltitle"></i></a>
                    </li>

                </ul>
                <div id="nt-title-container" class="navbar-left running-text visible-lg">
                    

                    <ul id="digital-clock" class="digital">
                        <div id="time">
    <script>
        document.getElementById('time').innerHTML = new Date().toLocaleString()
                + ' 星期' + '日一二三四五六'.charAt(new Date().getDay());
        setInterval(
                "document.getElementById('time').innerHTML=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());",
                1000);
    </script>
</div>
                    </ul>
                    <ul id="nt-title">
                        <li><i class="wi-day-lightning"></i>&#160;&#160;北京&#160;
                            <b>24°</b><i class="wi-Celsius"></i>&#160;; 
                        </li>
                        <li><i class="wi-day-lightning"></i>&#160;&#160;上海&#160;
                            <b>28°</b><i class="wi-Celsius"></i>&#160;;
                        </li>

                        <li><i class="wi-day-lightning"></i>&#160;&#160;内蒙古&#160;
                            <b>26°</b><i class="wi-Celsius"></i>&#160;;
                        </li>

                        <li><i class="wi-day-lightning"></i>&#160;&#160;海南&#160;
                            <b>31°</b><i class="wi-Celsius"></i>&#160;; 
                        </li>

                        <li><i class="wi-day-lightning"></i>&#160;&#160;四川&#160;
                            <b>29°</b><i class="wi-Celsius"></i>&#160;; 
                        </li>

                    </ul>
                </div>

                <ul style="margin-right:0;" class="nav navbar-nav navbar-right">
                    <li>
                        <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                            <img alt="" class="admin-pic img-circle" src="http://api.randomuser.me/portraits/thumb/men/10.jpg">欢迎您 <b class="caret"></b>
                        </a>
                        <ul style="margin-top:14px;" role="menu" class="dropdown-setting dropdown-menu">
                            <li>
                                <a href="#">
                                    <span class="entypo-user"></span>&#160;&#160;我的账户</a>
                            </li>
                            <li>
                                <a href="#">
                                    <span class="entypo-vcard"></span>&#160;&#160;账户设置</a>
                            </li>
                            <li>
                                <a href="#">
                                    <span class="entypo-lifebuoy"></span>&#160;&#160;帮助</a>
                            </li>
                            <li class="divider"></li>
                            <li>
                                <a href="/changepage/login.jsp">
                                    <span class="entypo-user"></span>&#160;&#160; 退出账户</a>
                            </li>
                        </ul>
                    </li>
                    <li>
                        <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                            <span class="icon-gear"></span>&#160;&#160;背景颜色</a>
                        <ul role="menu" class="dropdown-setting dropdown-menu">

                            <li class="theme-bg">
                                <div id="button-bg"></div>
                                <div id="button-bg2"></div>
                                <div id="button-bg3"></div>
                                <div id="button-bg5"></div>
                                <div id="button-bg6"></div>
                                <div id="button-bg7"></div>
                                <div id="button-bg8"></div>
                                <div id="button-bg9"></div>
                                <div id="button-bg10"></div>
                                <div id="button-bg11"></div>
                                <div id="button-bg12"></div>
                                <div id="button-bg13"></div>
                            </li>
                        </ul>
                    </li>
                    
                </ul>

            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container-fluid -->
    </nav>

    <!-- /END OF TOP NAVBAR -->

    <!-- SIDE MENU -->
    <div id="skin-select">
        <div id="logo">
            <h1>IMUT ATM<span>v2.2.7</span></h1>
            </h1>
        </div>

        <a id="toggle">
            <span class="entypo-menu"></span>
        </a>
        <div class="dark">
            <form action="#">
                <span>
                    <input type="text" name="search" value="" class="search rounded id_search" placeholder="Search Menu..." autofocus="">
                </span>
            </form>
        </div>

        <div class="search-hover">
            <form id="demo-2">
                <input type="search" placeholder="Search Menu..." class="id_search">
            </form>
        </div>


        <div class="search-hover">
            <form id="demo-2">
                <input type="search" placeholder="Search Menu..." class="id_search">
            </form>
        </div>




        <div class="skin-part">
            <div id="tree-wrap">
                <div class="side-bar">
                    <ul class="topnav menu-left-nest">
                        

                        
                        
                        
                    </ul>

                    <ul class="topnav menu-left-nest">
                        

                        
                        

                       
<li>
                                    <a class="tooltip-tip2 ajax-load" href="/changepage/UserIndex.jsp" title="Profile Page">
                                    <i class="icon-user"></i><span>用户信息</span></a>
                                </li>

                        

                        <li>
                            <a class="tooltip-tip" href="/changepage/UserChangePwd.jsp" title="Extra Pages">
                                <i class="icon-lock"></i>
                                <span>修改密码</span>
                            </a>
                          
                                <li>
                                    <a class="tooltip-tip2 ajax-load" href="/UserSerch" title="Blank Page">
                                    <i class="icon-media-record"></i><span>查询余额</span></a>
                                </li>
                                
                                <li>
                                    <a class="tooltip-tip2 ajax-load" href="/changepage/UserStore.jsp" title="Invoice">
                                    <i class="entypo-newspaper"></i><span>存款</span></a>
                                </li>
                                <li>
                                    <a class="tooltip-tip2 ajax-load" href="/changepage/UserFetch.jsp" title="Pricing Table">
                                    <i class="fontawesome-money"></i><span>取款</span></a>
                                </li>
                                <li>
                                    <a class="tooltip-tip2 ajax-load" href="/changepage/UserTransfer.jsp" title="Time Line">
                                    <i class="entypo-clock"></i><span>转账</span></a>
                                </li>
                                <li>
                                    <a class="tooltip-tip2" href="/serchDetaile" title="404 Error Page">
                                    <i class="icon-preview"></i><span>交易明细</span></a>
                                </li>
                                <li>
                                    <a class="tooltip-tip2" href="/changepage/login.jsp" title="login.jsp">
                                    <i class="icon-mail"></i><span>退卡</span></a>
                                </li>
                                
                         
                     

                        

                    </ul>

                    


                    
                </div>
            </div>
        </div>
    </div>
    <!-- END OF SIDE MENU -->



    <!--  PAPER WRAP -->
    <div class="wrap-fluid">
        <div class="container-fluid paper-wrap bevel tlbr">


            <!--/ TITLE -->

            <!-- BREADCRUMB -->
            <ul id="breadcrumb">
                <li>
                    <span class="entypo-home"></span>
                </li>
                <li><i class="fa fa-lg fa-angle-right"></i>
                </li>
                <li><a href="#" title="Sample page 1">首页</a>
                </li>
                <li><i class="fa fa-lg fa-angle-right"></i>
                </li>
                <li><a href="#" title="Sample page 1">交易明细</a>
                </li>
                
            </ul>

            <!-- END OF BREADCRUMB -->

            <div class="content-wrap">
                <div class="row">


                    <div class="col-sm-12">
                        <!-- BLANK PAGE-->

                        <h2 align="center"><b>IMUT BANK借记卡明细对账单</b></h2>
							<%
								SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
								request.setAttribute("date_time", df.format(new Date()));
							%>
							<h4 align="center">打印日期:${date_time }</h4>
                            <div class="body-nest" id="Blank_Page_Content">
									<div class="form_center">

                                    
                                    
               	</table> <table width="90%" border='2'>
		<tr align="center">
		<br><br>
			<th><font size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;卡&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></th>
			<th><font size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;日&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;期&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></th>
			<th><font size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;货&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;币&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></th>
			<th><font size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;交&nbsp;&nbsp;易&nbsp;&nbsp;金&nbsp;&nbsp;额&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></th>
			<th><font size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;账&nbsp;&nbsp;户&nbsp;&nbsp;余&nbsp;&nbsp;额&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></th>
		</tr>
		<c:forEach items="${pageBean.list }" var="user">
			<tr>
				<td>${user.icno }</td>
				<td>${user.rm_date }</td>
				<td>${user.rm_currency }</td>
				<td>${user.rm_balance }</td>
				<td>${user.rm_rest }</td>
			</tr>
		</c:forEach>
	</table>                
         
                                </div>
                                
                                
                                
                                
                                
                            </div>
                        </div>
                    </div>
                    <!-- END OF BLANK PAGE -->


                </div>
<%-- ${requestScope.pageBean.pageNum == 1} --%>
<!-- <input hidden="true" name="pageNum" value="1"/> -->
<%-- <c:if test="${pageBean.pageNum==0}">
	${pageContext.request.contextPath}/serchDetaile?pageNum=1
</c:if> --%>
<div align="center">
<br/>
<br/>
<br/>
<!-- ---------------------------------------------------------------------------------------------------------- -->
<%-- 构建分页导航 --%>
            <p style="font-size:20px; color:gray">共有${pageBean.totalRecord}条数据,共${pageBean.totalPage}页,当前为${pageBean.pageNum}页</p>
            <br/>
            <div style="font-size: 17px; color: black">
            <a href="${pageContext.request.contextPath}/serchDetaile?pageNum=1" style="font-color: green">首页</a>
            <%--如果当前页为第一页时,就没有上一页这个超链接显示 --%>
            <c:if test="${pageBean.pageNum ==1}">
                <c:forEach begin="${pageBean.start}" end="${pageBean.end}" step="1" var="i">
                    <c:if test="${pageBean.pageNum == i}">
                        ${i}
                    </c:if>                
                    <c:if test="${pageBean.pageNum != i}">
                        <a href="${pageContext.request.contextPath}/serchDetaile?pageNum=${i}">${i}</a>                                        
                    </c:if>                        
                </c:forEach>
                <a href="${pageContext.request.contextPath}/serchDetaile?pageNum=${pageBean.pageNum+1}">下一页</a>
            </c:if>
            
            <%--如果当前页不是第一页也不是最后一页,则有上一页和下一页这个超链接显示 --%>
            <c:if test="${pageBean.pageNum > 1 && pageBean.pageNum < pageBean.totalPage}">
                <a href="${pageContext.request.contextPath}/serchDetaile?pageNum=${pageBean.pageNum-1}">上一页</a>
                <c:forEach begin="${pageBean.start}" end="${pageBean.end}" step="1" var="i">    
                    <c:if test="${pageBean.pageNum == i}">
                        ${i}
                    </c:if>            
                    <c:if test="${pageBean.pageNum != i}">
                        <a href="${pageContext.request.contextPath}/serchDetaile?pageNum=${i}">${i}</a>                                        
                    </c:if>                        
                </c:forEach>
                <a href="${pageContext.request.contextPath}/serchDetaile?pageNum=${pageBean.pageNum+1}">下一页</a>    
            </c:if>
            
            <%-- 如果当前页是最后一页,则只有上一页这个超链接显示,下一页没有 --%>
            <c:if test="${pageBean.pageNum!=1 &&pageBean.pageNum == pageBean.totalPage}">
                <a href="${pageContext.request.contextPath}/serchDetaile?pageNum=${pageBean.pageNum-1}">上一页</a>
                <c:forEach begin="${pageBean.start}" end="${pageBean.end}" step="1" var="i">
                    <c:if test="${pageBean.pageNum == i}">
                        ${i}
                    </c:if>
                    <c:if test="${pageBean.pageNum != i}">
                        <a href="${pageContext.request.contextPath}/serchDetaile?pageNum=${i}">${i}</a>                                        
                    </c:if>                
                </c:forEach>
            </c:if>
            <%--尾页 --%>
            <a href="${pageContext.request.contextPath}/serchDetaile?pageNum=${pageBean.totalPage}">尾页</a>
		</div>
                <!-- /END OF CONTENT -->
	<!-- ---------------------------------------------------------------------------------------------------------------- -->
</div>

                <!-- FOOTER -->
                <div class="footer-space"></div>
                <div id="footer">
                <div class="devider-footer-left"></div>
                <div class="time">
                    <p id="spanDate">
                    <p id="clock">
                </div>
                <div class="copyright">本网站基于百度查询开发 <a href="http://www.baidu.com/" title="百度" target="_blank">百度</a> All Rights Reserved</div>
                <div class="devider-footer"></div>

            </div>
                <!-- / END OF FOOTER -->


            </div>
        </div>
        <!--  END OF PAPER WRAP -->

        <!-- RIGHT SLIDER CONTENT -->
        <div class="sb-slidebar sb-right">
            <div class="right-wrapper">
                <div class="row">
                    <h3>
                        <span><i class="entypo-gauge"></i>&nbsp;&nbsp;MAIN WIDGET</span>
                    </h3>
                    <div class="col-sm-12">

                        <div class="widget-knob">
                            <span class="chart" style="position:relative" data-percent="86">
                                <span class="percent"></span>
                            </span>
                        </div>
                        <div class="widget-def">
                            <b>Distance traveled</b>
                            <br>
                            <i>86% to the check point</i>
                        </div>

                        <div class="widget-knob">
                            <span class="speed-car" style="position:relative" data-percent="60">
                                <span class="percent2"></span>
                            </span>
                        </div>
                        <div class="widget-def">
                            <b>The average speed</b>
                            <br>
                            <i>30KM/h avarage speed</i>
                        </div>


                        <div class="widget-knob">
                            <span class="overall" style="position:relative" data-percent="25">
                                <span class="percent3"></span>
                            </span>
                        </div>
                        <div class="widget-def">
                            <b>Overall result</b>
                            <br>
                            <i>30KM/h avarage Result</i>
                        </div>
                    </div>
                </div>
            </div>

            <div style="margin-top:0;" class="right-wrapper">
                <div class="row">
                    <h3>
                        <span><i class="entypo-chat"></i>&nbsp;&nbsp;CHAT</span>
                    </h3>
                    <div class="col-sm-12">
                        <span class="label label-warning label-chat">Online</span>
                        <ul class="chat">
                            <li>
                                <a href="#">
                                    <span>
                                        <img alt="" class="img-chat img-circle" src="http://api.randomuser.me/portraits/thumb/men/20.jpg">
                                    </span><b>Dave Junior</b>
                                    <br><i>Last seen : 08:00 PM</i>
                                </a>
                            </li>
                            <li>
                                <a href="#">
                                    <span>
                                        <img alt="" class="img-chat img-circle" src="http://api.randomuser.me/portraits/thumb/men/21.jpg">
                                    </span><b>Kenneth Lucas</b>
                                    <br><i>Last seen : 07:21 PM</i>
                                </a>
                            </li>
                            <li>
                                <a href="#">
                                    <span>
                                        <img alt="" class="img-chat img-circle" src="http://api.randomuser.me/portraits/thumb/men/22.jpg">
                                    </span><b>Heidi Perez</b>
                                    <br><i>Last seen : 05:43 PM</i>
                                </a>
                            </li>


                        </ul>

                        <span class="label label-chat">Offline</span>
                        <ul class="chat">
                            <li>
                                <a href="#">
                                    <span>
                                        <img alt="" class="img-chat img-offline img-circle" src="http://api.randomuser.me/portraits/thumb/men/23.jpg">
                                    </span><b>Dave Junior</b>
                                    <br><i>Last seen : 08:00 PM</i>
                                </a>
                            </li>
                            <li>
                                <a href="#">
                                    <span>
                                        <img alt="" class="img-chat img-offline img-circle" src="http://api.randomuser.me/portraits/thumb/women/24.jpg">
                                    </span><b>Kenneth Lucas</b>
                                    <br><i>Last seen : 07:21 PM</i>
                                </a>
                            </li>
                            <li>
                                <a href="#">
                                    <span>
                                        <img alt="" class="img-chat img-offline img-circle" src="http://api.randomuser.me/portraits/thumb/men/25.jpg">
                                    </span><b>Heidi Perez</b>
                                    <br><i>Last seen : 05:43 PM</i>
                                </a>
                            </li>
                            <li>
                                <a href="#">
                                    <span>
                                        <img alt="" class="img-chat img-offline img-circle" src="http://api.randomuser.me/portraits/thumb/women/25.jpg">
                                    </span><b>Kenneth Lucas</b>
                                    <br><i>Last seen : 07:21 PM</i>
                                </a>
                            </li>
                            <li>
                                <a href="#">
                                    <span>
                                        <img alt="" class="img-chat img-offline img-circle" src="http://api.randomuser.me/portraits/thumb/men/26.jpg">
                                    </span><b>Heidi Perez</b>
                                    <br><i>Last seen : 05:43 PM</i>
                                </a>
                            </li>


                        </ul>
                    </div>
                </div>
            </div>
        </div>

        <!-- END OF RIGHT SLIDER CONTENT-->


        <!-- MAIN EFFECT -->
        <script type="text/javascript" src="assets/js/preloader.js"></script>
        <script type="text/javascript" src="assets/js/bootstrap.js"></script>
        <script type="text/javascript" src="assets/js/app.js"></script>
        <script type="text/javascript" src="assets/js/load.js"></script>
        <script type="text/javascript" src="assets/js/main.js"></script>


</div></body>

</html>

创建一个PageBean对象,封装这些数据:

package com.atm.pojo;
import java.util.List;

public class PageBean<T> {

    private int pageNum;//当前页页码,从请求传过来
    private int pageSize; //每页显示的数据条数
    private int totalRecord;//总的记录条数,查询数据库得到的数据

    //需要计算得来
    private  int totalPage; //总页数 通过总条数和每页显示多少条计算得来
    private int startIndex;//从哪开始拿

    //把每页要显示的数据放集合里
    private  List<T> list;

    //分页显示的页数  1-5中的1和5

    private  int start;
    private int end;

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalRecord() {
        return totalRecord;
    }

    public void setTotalRecord(int totalRecord) {
        this.totalRecord = totalRecord;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getStartIndex() {
        return startIndex;
    }

    public void setStartIndex(int startIndex) {
        this.startIndex = startIndex;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getStart() {
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public int getEnd() {
        return end;
    }

    public void setEnd(int end) {
        this.end = end;
    }

    public PageBean(int pageNum, int pageSize, int totalRecord){
        this.pageNum=pageNum;
        this.pageSize=pageSize;
        this.totalRecord=totalRecord;

        //totalpage 总页数
        if(totalRecord%pageSize==0){
            //说明整除,正好每页显示pagesize条数据
            this.totalPage=totalRecord/pageSize;
        }else{
            //不整除,就要多加一页,显示多余的数据
            this.totalPage=totalRecord/pageSize+1;
        }
        //开始索引
        this.startIndex=(pageNum-1)*pageSize;
        this.start=1;
        this.end=5;

        if(totalPage<=5){
            this.end=this.totalPage;
        }else{
            this.start=pageNum-2;
            this.end=pageNum+2;

            if(start<=0){
            //比如当前页是第一页,或者第二页,就不如和这个规则
                this.start=1;
                this.end=5;
            }
            if(end >=this.totalPage){
                //比如当前页是倒数第二页或者最后一页,也同样不符合上面这个规则
                this.end=totalPage;
                this.start=end-4;
            }
        }

    }

}

之前我们把查询交易明细的代码都写到Userservice中了,其实应该写到RunMessageService中,对应的数据层和实现类也是同样的操作~

然后对交易记录的Servlet进行修改,插入分页功能:

package com.atm.servlet;

import com.atm.pojo.PageBean;
import com.atm.pojo.RunMessage;
import com.atm.pojo.User;
import com.atm.service.RunMessageService;
import com.atm.service.UserService;
import com.atm.service.impl.RunMessageServiceImpl;
import com.atm.service.impl.UserServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;


//查询交易记录
@WebServlet("/serchDetaile")
public class SerchDetaileServlet extends HttpServlet {

    private RunMessageService runMessageService=new RunMessageServiceImpl();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    User user =(User)request.getSession().getAttribute("ua");
        try {
            //分页处理
            //获得页码
            String pageNum=request.getParameter("pageNum");
            int page=1;
            if(pageNum!=null){
                page=Integer.parseInt(pageNum);
            }
            //每页显示的条数
            int pagesize=5;
            //计算分页的总条数
            int totalRecord= runMessageService.countRunmessage(user.getIcno());
            //封装pagebean对象
            PageBean<RunMessage> pageBean=new PageBean<>(page,pagesize,totalRecord);
            //查询当前页的数据,并设置到pageBean中返回
            List<RunMessage> lists =runMessageService.findRunMessageByPage(user.getIcno(),page,pagesize);
            pageBean.setList(lists);
            request.getSession().setAttribute("pageBean",pageBean);
            response.sendRedirect("/changepage/UserDetaile.jsp");
        } catch (Exception e) {
           e.printStackTrace();
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doPost(request,response);
    }
}

接口:

    //查询交易记录总条数
    public  int countRunmessage(String icno) throws Exception{
        return runMessageDao.countRunMessage(icno);
    }


    //查询当前页数据
    public List<RunMessage> findRunMessageByPage(String icno,int page, int pagesize)   throws Exception{
        return runMessageDao.findRunMessageByPage(icno,page,pagesize);
    }

数据层:

//用户交易记录总条数
    public int countRunMessage(String icno)  throws Exception{
        Connection connection=DBUtils.getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement("select count(1) from runmessage where icno=?");
        preparedStatement.setString(1,icno);
        ResultSet rs=  preparedStatement.executeQuery();
        int totalRecord=0;
        if (rs.next()){
            totalRecord=rs.getInt(1);
        }
        DBUtils.release(connection,preparedStatement,null);
        return totalRecord;
    }

    //查询当前页的交易记录
    public List<RunMessage> findRunMessageByPage(String icno,int page, int pagesize) throws Exception {
        Connection connection=DBUtils.getConnection();
        int startIndex =(page-1)*pagesize;
        PreparedStatement preparedStatement = connection.prepareStatement("select * from runmessage where icno=? limit ?,?");
        preparedStatement.setString(1,icno);
        preparedStatement.setInt(2,startIndex);
        preparedStatement.setInt(3,pagesize);
        ResultSet rs=  preparedStatement.executeQuery();
        List<RunMessage> lists=new ArrayList<>();
        while (rs.next()){
            RunMessage runMessage=new RunMessage();
            runMessage.setId(rs.getInt(1));
            runMessage.setIcno(rs.getString(2));
            runMessage.setRm_date(rs.getString(3));
            runMessage.setRm_currency(rs.getString(4));
            runMessage.setRm_balance(rs.getDouble(5));
            runMessage.setRm_rest(rs.getDouble(6));
            lists.add(runMessage);
        }
        DBUtils.release(connection,preparedStatement,null);
        return lists;
    }

再随便添加几条数据方便测试效果:

 重启一下系统,然后就发现功能实现啦!~

 实现代码已上传~

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/788332.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

智能照明的特点及控制系统的实际案例分享

安科瑞虞佳豪 壹捌柒陆壹伍玖玖零玖叁 智能照明控制系统是利用先进电磁调压及电子感应技术&#xff0c;以公共照明统一格智能为平台&#xff0c;对供电进行实时监控与跟踪&#xff0c;自动平滑地调节电路的电压和电流幅度&#xff0c;改善照明电路中不平衡负荷所带来的额外功…

c++11/c++98动态规划入门第5课,经典DP问题 --- 区间

第1题 取数问题 查看测评数据信息 有一排N个数&#xff0c;你和小明2个人玩游戏&#xff0c;每个人轮流从2端取数&#xff0c;每次可以从左或右取&#xff0c;不能从中间取。你取的所有的数的和是你的得分&#xff0c;小明取的所有的数的和是小明的得分。如果你先取&#x…

【MySQL】MySQL HeatWave 介绍

HeatWave是一个分布式、可扩展、无共享、内存中、混合柱状的查询处理引擎&#xff0c;专为获得极致性能而设计。可以通过向MySQL数据库系统添加一个HeatWave集群来启用它。 HeatWave 是一种大规模并行、高性能内存查询加速器&#xff0c;可将分析工作负载、混合工作负载和机器…

5.string变量-读取一行

C里面的读一行的用法。getline&#xff08;cin,addr&#xff09;; 从标准输入设备cin&#xff0c;读取一行字符串保存到字符串变量addr中 如果用户直接回车什么都不读取就没有任何数据输入 读一行直到遇到回车符&#xff0c;注意不包括回车符。 判断字符串是不是空的 addr.em…

学生管理系统-06Echarts

一、Echarts简介 1、什么是echarts ECharts是一款基个基于 JavaScript 的开源可视化图表库 官网地址&#xff1a;Apache ECharts 国内镜像&#xff1a;ISQQW.COM x ECharts 文档&#xff08;国内同步镜像&#xff09; - 配置项 示例&#xff1a;echarts图表集 2、第一个E…

[面试官,你坐好],今天我给你吹下卡顿监控

这是一篇面试总结稿&#xff0c;根据之前的面试过程以一种模拟面试的风格进行阐述。 面试官: 自我介绍下 诶&#xff1f;这面试官头发还比较多&#xff0c;应该不牛逼&#xff0c;心里踏实了不少。我: 面试官你好&#xff0c;我叫**&#xff0c;5年工作经验。曾经跟OPPO产品PK&…

Alchemy Catalyst 2023 Crack

Alchemy Catalyst 2023 Crack Alchemy CATALYST是一个可视化的本地化环境&#xff0c;支持本地化工作流程的各个方面。它帮助组织加快本地化进程&#xff0c;比竞争对手更快地进入新市场&#xff0c;并为他们创造新的收入机会。 创建全球影响力 高质量的产品和服务翻译对跨国组…

人才缺口将达 6.7 万人?半导体行业“后继无人”,美国危?

根据美国半导体行业协会&#xff08;SIA&#xff09;和牛津经济研究所&#xff08;Oxford Economics&#xff09;联合编制的一项研究报告指出&#xff0c;到2030年&#xff0c;美国半导体行业预计面临约6.7万名人才缺口。 根据预测&#xff0c;到2029年底&#xff0c;美国芯片行…

1.Flink概述

1.1 技术架构 应用框架层: 在API层之上构建的满足特定应用场景的计算框架&#xff0c;总体上分为流计算和批处理两类应用框架。API 层&#xff1a; Flink对外提供能力的接口 &#xff0c;实现了面向流计算的DataStream API和面向批处理的DataSet API。运行时层&#xff1a;Flin…

基于Java+SpringBoot+vue前后端分离小徐影城管理系统设计实现

博主介绍&#xff1a;✌全网粉丝30W,csdn特邀作者、博客专家、CSDN新星计划导师、Java领域优质创作者,博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌ &#x1f345;文末获取源码联系&#x1f345; &#x1f447;&#x1f3fb; 精彩专…

标准IO函数练习

一、实现登录功能。 自定义一个usr.txt&#xff0c;手动输入账户密码&#xff0c;格式如下&#xff1a;账户 密码 例如&#xff1a; zhangsan 12345 lisi abcde wangwu abc123 需求如下&#xff1a; 从终端获取账户密码&#xff0c;与文件中的账户密码比较若终端输入的账户…

好看的思维导图模板有哪些?分享这几款

好看的思维导图模板有哪些&#xff1f;思维导图是一种非常实用的工具&#xff0c;可以帮助我们更好地组织和理解信息。然而&#xff0c;如果你想让你的思维导图看起来更好看&#xff0c;吸引人眼球&#xff0c;那么选择一个好的思维导图模板是非常重要的。 在众多的思维导图制作…

【STM32】 强大的 STM32Cube 生态 STM32CubeIDE 无伤速通

本文介绍的软件&#xff0c;均可以在ST官网st.com免费下载&#xff08;你需要注册登录&#xff09;&#xff0c;首选官网下载最新版本&#xff0c;如果有问题&#xff0c;可以在我的公众号回复&#xff1a;Cube&#xff0c;获取截止今日的最新版本软件安装包。 目录 一、STM32C…

传统域名与区块链域名的区别是什么?

区块链技术的发展&#xff0c;不仅带来了数字货币的兴起&#xff0c;还催生了一种新型的互联网域名——Web3 域名。Web3 域名作为一种新兴的域名体系&#xff0c;与传统的域名有着很大的区别。今天&#xff0c;我们就来探讨一下传统域名与区块链域名的区别。 首先&#xff0c;让…

查看docker容器启动参数

查看docker启动参数 1、查看docker容器的自启动策略2、查看docker容器的日志滚动清理策略 以下配置命令以redis容器为例 1、查看docker容器的自启动策略 docker inspect --format{{json .HostConfig.RestartPolicy}} redis输出的name是always 表示此容器是开机自启动的&#x…

蓝桥杯上岸必背!!!(第六期树与图的遍历)

第六期&#xff1a;树与图的遍历 &#x1f525; &#x1f525; &#x1f525; 蓝桥杯热门考点模板总结来啦✨ ~ 你绝绝绝绝绝绝对不能错过的常考树与图的遍历模板 &#x1f4a5; ❗️ ❗️ ❗️ 大家好 我是寸铁 &#x1f4aa; 祝大家4月8号蓝桥杯上岸 ☀️ 还没背熟模板…

2.1数据结构——线性表

一、定义 线性表是具有相同数据类型的n&#xff08;n>0&#xff09;个数据元素的有限序列&#xff0c;&#xff08;n表示表长&#xff0c;n0为空表&#xff09; 用L表示&#xff1a; 位序&#xff1a;线性表中的“第i个” a1是表头元素&#xff1b;an是表尾元素 除第一个…

2023 年牛客多校第三场题解

A World Fragments I 题意&#xff1a;给定两个二进制数 x , y x,y x,y&#xff0c;每次可以选择 x x x 二进制表达中的其中一位 b b b&#xff0c;然后执行 x ← x − b x \leftarrow x-b x←x−b 或 x ← x b x \leftarrow xb x←xb。问 x x x 最少经过多少次操作变成…

高速数据采集专家-FMC140【产品手册】

FMC140是一款具有缓冲模拟输入的低功耗、12位、双通道&#xff08;5.2GSPS/通道&#xff09;、单通道10.4GSPS、射频采样ADC模块&#xff0c;该板卡为FMC标准&#xff0c;符合VITA57.1规范&#xff0c;该模块可以作为一个理想的IO单元耦合至FPGA前端&#xff0c;8通道的JESD204…

第一启富金:现货黄金市场等待央行决议 非美商品‘弱不禁风’

第一启富金基本面分析&#xff1a; 中国纸黄金交易通显示&#xff0c;全球最大黄金上市交易基金(ETF)截至07月22日持仓量为919.00吨&#xff0c;较上日增持5.20吨&#xff0c;本月止净减持2.90吨。 在俄罗斯上周退出黑海谷物协议&#xff0c;摧毁了乌克兰通往基辅的一条出口路线…