一,项目简介
本项目主要实现一个模拟ATM机存款、取款、转账功能的一个系统,可以查看打印交易明细,后台用户可以管理用户账户卡信息。本系统主要是针对计算机专业的学生做课程设计或课程期未作业使用。功能完整,界面美观大方。如果你的课程设计或作业是关于ATM机存取款方面的,可以考虑使用。本系统包含完整源码和数据库一份,并配套文档说明一份。
二,环境介绍
开发工具:IDEA / ECLIPSE
数据库:MYSQL5.7
应用服务器:TOMCAT8.5.31
后台开发技术:JSP、Servlet
前端开发技术:javascript、css、bootstrap
三,系统展示
前端页面
用户登陆
前端用户登陆后主页显示用户信息
修改密码
查询银行卡余额
银行卡存款
银行卡取款:取款金额不得大于当前余额
银行卡转账
分页查询交易明细
后台管理功能
用户登陆
银行卡用户列表:可以实现模糊搜索
用户信息修改删除
银行卡用户添加
四,核心代码展示
用户登陆代码
package com.atm.servlet; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.atm.service.UserService; import com.atm.service.impl.UserServiceimpl; public class LoginServlet extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); resp.setContentType("text/html;charset=utf-8"); String name = req.getParameter("name"); String pwd = req.getParameter("password"); System.out.println(name+"----"+pwd); UserService us = new UserServiceimpl(); int result = us.login(name, pwd, req); System.out.println(result); if(result==1){ System.out.println("用户登录成功!"); resp.sendRedirect("list"); }else if(result==0){ System.out.println("用户登录失败"); req.setAttribute("error", "密码错误"); req.getRequestDispatcher("changepage/login.jsp").forward(req, resp); }else{ System.out.println("LoginServlet.doGet(我是result==其他)"); req.setAttribute("error", "用户名不存在"); req.getRequestDispatcher("changepage/login.jsp").forward(req, resp); } } public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doGet(req,resp); } }
用户模拟取款代码
package com.atm.servlet; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import com.atm.dao.BeanUserDao; import com.atm.dao.impl.BeanUserDaoImpl; import com.atm.pojo.RunMessage; import com.atm.service.BeanUserService; import com.atm.service.impl.BeanUserServiceImpl; @WebServlet("/UserFetch") public class UserFetchServlet extends HttpServlet { private static final long serialVersionUID = 1L; @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); resp.setContentType("text/html;charset=uttf-8"); int fetchNum = Integer.parseInt(req.getParameter("fetchNum")); HttpSession session = req.getSession(); Object obj = session.getAttribute("userAccount"); BeanUserService us = new BeanUserServiceImpl(); double Money = us.serchBalance((String)obj); RunMessage rm = new RunMessage(); BeanUserDao bud = new BeanUserDaoImpl(); double fushu = -fetchNum; if(session!=null && fetchNum<=2000 && Money-fetchNum>=0&&fetchNum%50==0 && fetchNum>0) { rm.setICno((String)obj); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 rm.setRM_date(df.format(new Date())); rm.setRM_Currency("人民币"); rm.setRM_Balance(fushu); System.out.println("用户:"+(String)obj+" 取款"+fetchNum+"元"); rm.setRM_Rest(us.serchBalance((String)obj)-fetchNum); BeanUserService bus = new BeanUserServiceImpl(); req.getSession().setAttribute("balance", Money); bus.fetchMoney((String)obj, fetchNum); bud.RunMessage(rm); // req.getRequestDispatcher("serch").forward(req, resp); resp.sendRedirect("/Final/UserSerch"); }else if(fetchNum>2000){ req.getSession().setAttribute("error2", "取出失败,金额不得超过2000元"); // req.getRequestDispatcher("UserJsp/fetchMoney.jsp").forward(req, resp); //这个地方必须是重定向,因为 UserJsp/fetchMoney.jsp 这个jsp中提交地址是<form action="../fetch"> //,它会进行一次向上跳转,所以需要重定向而不是请求转发,否则地址栏将会变成 //http://localhost:8080/fetch?fetchNum=你输入的取钱金额,应该是: //http://localhost:8080/course/fetch?fetchNum=你输入的取钱金额 resp.sendRedirect("/Final/changepage/UserFetch.jsp"); }else if(fetchNum<0) { req.getSession().setAttribute("error2", "取款金额必须大于0!"); resp.sendRedirect("/Final/changepage/UserFetch.jsp"); }else if(fetchNum%50!=0) { req.getSession().setAttribute("error2", "只能取出50或100元现金的倍数!"); resp.sendRedirect("/Final/changepage/UserFetch.jsp"); }else if(Money-fetchNum<0) { req.getSession().setAttribute("error2", "卡内余额不足!"); resp.sendRedirect("/Final/changepage/UserFetch.jsp"); } } }
package com.atm.servlet; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import com.atm.dao.BeanUserDao; import com.atm.dao.impl.BeanUserDaoImpl; import com.atm.pojo.RunMessage; import com.atm.service.BeanUserService; import com.atm.service.impl.BeanUserServiceImpl; @WebServlet("/UserStore") public class UserStoreServlet extends HttpServlet { private static final long serialVersionUID = 1L; @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); resp.setContentType("text/html;charset=utf-8"); RunMessage rm = new RunMessage(); BeanUserDao bud = new BeanUserDaoImpl(); int result = 0; int saveNum = Integer.parseInt(req.getParameter("saveNum")); HttpSession session = req.getSession(); Object obj = session.getAttribute("userAccount"); BeanUserService us = new BeanUserServiceImpl(); double Money = us.serchBalance((String)obj); if(session!=null && saveNum<=2000 && saveNum%50==0 && saveNum >0) { BeanUserService bus = new BeanUserServiceImpl(); bus.saveMoney((String)obj, saveNum); rm.setICno((String)obj); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 rm.setRM_date(df.format(new Date())); rm.setRM_Currency("人民币"); rm.setRM_Balance(saveNum); rm.setRM_Rest(us.serchBalance((String)obj)); bud.RunMessage(rm); req.getSession().setAttribute("balance", Money); List<RunMessage> list = bud.SelMessage((String)obj); req.getServletContext().setAttribute("RunMessage", list); // req.getRequestDispatcher("serch").forward(req, resp); resp.sendRedirect("/Final/UserSerch"); System.out.println("用户:"+(String)obj+" 存款"+saveNum+"元"); // resp.sendRedirect("serch"); }else if (result == 4 && session != null) { // req.getRequestDispatcher("UserJsp/saveMoney.jsp").forward(req, resp); resp.sendRedirect("/Final/changepage/UserStore.jsp"); }else if(saveNum>2000){ req.getSession().setAttribute("error3", "存储失败,金额不得超过2000元"); // req.getRequestDispatcher("UserJsp/saveMoney.jsp").forward(req, resp); // resp.sendRedirect("UserJsp/saveMoney.jsp"); resp.sendRedirect("/Final/changepage/UserStore.jsp"); }else if(saveNum%50!=0) { req.getSession().setAttribute("error3", "只能投入50元或100元的钞票!"); // req.getRequestDispatcher("UserJsp/saveMoney.jsp").forward(req, resp); // resp.sendRedirect("UserJsp/saveMoney.jsp"); resp.sendRedirect("/Final/changepage/UserStore.jsp"); }else if(saveNum<0) { req.getSession().setAttribute("error3", "存款金额必须大于0!"); // req.getRequestDispatcher("UserJsp/saveMoney.jsp").forward(req, resp); // resp.sendRedirect("UserJsp/saveMoney.jsp"); resp.sendRedirect("/Final/changepage/UserStore.jsp"); } } }
package com.atm.servlet; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import com.atm.dao.BeanUserDao; import com.atm.dao.impl.BeanUserDaoImpl; import com.atm.pojo.RunMessage; import com.atm.service.BeanUserService; import com.atm.service.impl.BeanUserServiceImpl; @WebServlet("/UserTransfer") public class UserTransferServlet extends HttpServlet { private static final long serialVersionUID = 1L; @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); resp.setContentType("text/html;charset=utf-8"); BeanUserDao budin = new BeanUserDaoImpl(); BeanUserDao budout = new BeanUserDaoImpl(); RunMessage rm1 = new RunMessage(); RunMessage rm2 = new RunMessage(); String transferIn = req.getParameter("transferIn"); double transferNum = Double.parseDouble(req.getParameter("transferNum")); HttpSession session = req.getSession(); Object obj = session.getAttribute("userAccount"); double fushu = -transferNum; BeanUserService us = new BeanUserServiceImpl(); if(transferNum<10000 && transferNum>0 && us.serchBalance((String)obj)-transferNum>=0) { us.transfer((String)obj, transferIn, transferNum); rm1.setICno((String)obj); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 rm1.setRM_date(df.format(new Date())); rm1.setRM_Currency("人民币"); rm1.setRM_Balance(fushu); rm1.setRM_Rest(us.serchBalance((String)obj)); rm2.setICno(transferIn); rm2.setRM_date(df.format(new Date())); rm2.setRM_Currency("人民币"); rm2.setRM_Balance(transferNum); rm2.setRM_Rest(us.serchBalance(transferIn)); budout.RunMessage(rm1); budin.RunMessage(rm2); List<RunMessage> list = budout.SelMessage((String)obj); List<RunMessage> list1 = budin.SelMessage(transferIn); req.getServletContext().setAttribute("RunMessage", list); req.getServletContext().setAttribute("RunMessage", list1); System.out.println("用户:"+(String)obj+" 转账"+transferNum+"元"); resp.getWriter().write("转账成功 3s后自动跳转回主页... ..."); resp.setHeader("refresh", "3,url=/Final/UserSerch"); // req.getRequestDispatcher("serch").forward(req, resp); // resp.sendRedirect("/Final/UserSerch"); }else if(us.serchBalance((String)obj)-transferNum<0){ req.getSession().setAttribute("error4", "抱歉,余额不足!"); resp.sendRedirect("/Final/changepage/UserTransfer.jsp"); }else if(transferNum > 10000) { req.getSession().setAttribute("error4", "转账金额不得高于10,000元!"); resp.sendRedirect("/Final/changepage/UserTransfer.jsp"); }else if(transferNum < 0 ) { req.getSession().setAttribute("error4", "请重新输入!"); resp.sendRedirect("/Final/changepage/UserTransfer.jsp"); } } }
五,项目总结
本系统仿照银行ATM取款机的功能,通过WEB的形式进行开发实现,功能完整,界面简洁大方,并可通过CSS自由切换系统背景界面风格,比较适合作课程设计或期未作业使用。