基于Javaweb实现ATM机系统开发实战(十三)交易记录查看实现

老规矩,先看前端传递怎样的数据,已经把要展示数据的变量名都改了:

<%@ 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.*"%> 




    
    IMUT_BANK ATM WelCome!!
    
    
    
    
    

    
    
    

    
    
    
    
    




    
    
 

IMUT BANK借记卡明细对账单

<% SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 request.setAttribute("date_time", df.format(new Date())); %>

打印日期:${date_time }



       卡      号               日      期               货      币               交  易  金  额               账  户  余  额       
${user.icno } ${user.rm_date } ${user.rm_currency } ${user.rm_balance } ${user.rm_rest }
<%-- ${requestScope.pageBean.pageNum == 1} --%> <%-- ${pageContext.request.contextPath}/serchDetaile?pageNum=1 --%>



<%-- 构建分页导航 --%>

共有${pageBean.totalRecord}条数据,共${pageBean.totalPage}页,当前为${pageBean.pageNum}页


首页 <%--如果当前页为第一页时,就没有上一页这个超链接显示 --%> ${i} ${i} 下一页 <%--如果当前页不是第一页也不是最后一页,则有上一页和下一页这个超链接显示 --%> 上一页 ${i} ${i} 下一页 <%-- 如果当前页是最后一页,则只有上一页这个超链接显示,下一页没有 --%> 上一页 ${i} ${i} <%--尾页 --%> 尾页

创建servlet接受和处理请求:

package com.atm.servlet;

import com.atm.pojo.RunMessage;
import com.atm.pojo.User;
import com.atm.service.UserService;
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 UserService userService=new UserServiceImpl();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    User user =(User)request.getSession().getAttribute("ua");
        try {
            List runMessages= userService.findRunMessage(user.getIcno());
            request.getSession().setAttribute("RunMessage",runMessages);
            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  List findRunMessage (String icno) throws Exception;

实现类:

    //查询用户交易记录
    public  List findRunMessage (String icno) throws Exception{
        return userDao.findRunMessage(icno);
    }

数据层:

   //查询用户交易明细
    public List findRunMessage(String icno) throws Exception {
        Connection connection=DBUtils.getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement("select * from runmessage where icno=?");
        preparedStatement.setString(1,icno);
        ResultSet rs=  preparedStatement.executeQuery();
        List  list=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));
            list.add(runMessage);
        }
        DBUtils.release(connection,preparedStatement,null);
        return list;
    }

然后重启系统,测试一下:

然后就发现交易明细正常显示啦~~

基于Javaweb实现ATM机系统开发实战(十三)交易记录查看实现_第1张图片

 实现代码已上传~

你可能感兴趣的:(JAVA学习笔记,java)