Java小项目-银行用户管理系统

这是一个使用Java编写的银行用户管理系统,具备用户登录、注册、个人信息显示、密码修改、银行卡管理、充值、提现、转账等功能。系统将用户、银行卡及转账流水数据存储到Mysql数据库,并提供了相应的控制器、 Dao层、Service接口及其实现类,以及多个视图类用于界面交互。项目还包含了测试类和数据库连接功能。
摘要由CSDN通过智能技术生成


前言

银行用户管理系统是由我的另一篇博客项目 Java实训项目——网银管理系统改编而来。 与之不同的是,这个小项目新增了 转账流水功能, 并且运用了 集合,JavaSpring,Mysql数据库和JDBC。 虽然大同小异,但亦有可取之处。

一. 功能

  1. 登陆

  2. 注册

  3. 首页

  4. 个人信息显示

  5. 修改密码

  6. 添加银行卡

  7. 银行卡查看

  8. 充值

  9. 提现

  10. 转账

  11. 用户管理

  12. 转账流水

把用户信息,银行卡信息和转账流水(包括充值,提现和转账)都存入数据库之中,在根据功能合理的使用这些数据。
详细的功能介绍在上一篇项目博客中已经介绍过了 ——网银管理系统。

二. 代码

类与接口的存放截图

银行卡数据

在这里插入图片描述

转账流水数据

在这里插入图片描述

用户数据

在这里插入图片描述

BanksController

package com.vector.controller;

import com.vector.entity.Banks;
import com.vector.service.BanksService;
import com.vector.service.impl.BanksServiceImpl;

import java.util.List;

public class BanksController {
   
    private BanksServiceImpl service =new BanksServiceImpl();
    public boolean addBanks(Banks banks){
   
        return service.addBanks(banks);
    }
    public List<Banks> showBanksByTel(String tel){
   
        return service.showBanksByTel(tel);
    }
    public boolean deleteMoney(String banksNum,double money){
   
        return service.deleteMoney(banksNum,money);
    }
    public boolean addMoney(String banksNum,double money){
   
        return service.addMoney(banksNum,money);
    }
    public boolean moveMoney(String banksNum1,String banksNum2,double money){
   
        return  service.moveMoney(banksNum1,banksNum2,money);
    }


    public boolean chickNUm( String num) {
   
        return  service.chickNUm(num);
    }
}

UserController

package com.vector.controller;

import com.vector.entity.Banks;
import com.vector.entity.User;
import com.vector.service.UserService;
import com.vector.service.impl.UsersServiceImpl;

import java.sql.SQLException;
import java.util.List;

// 用户管理
public class UserController {
   
    private UserService userService =new UsersServiceImpl();
    public User userLog(String tel,String pwd)  {
   

        return userService.findUSerByTelAdnpwd(tel,pwd);
    }
//    注册
//String name, String cardNum, String tel, String pwd, String email, double money, String relName
    public boolean addUser(String name, String cardNum, String tel, String pwd, String email, String relName){
   
        User u =new User(name,cardNum,tel,pwd,email,0,relName);
        return userService.addUsers(u);
    }

    public boolean isExistTel(String tel) {
   
        return userService.isExistTel(tel);
    }
    public boolean isExistEmail(String email){
   
        return userService.isExistEmail(email);
    }


    public boolean updatePwd(String tel,String odlPwd,String pwd){
   
        return userService.updatePwd(tel,pwd);
    }
    public boolean addMoney(String tel,double money){
   

        return userService.addMoney(tel,money);
    }
    public boolean deleteMoney(String tel,double money){
   
        return userService.deleteMoney(tel,money);
    }
    public List<User> showUserTel(String tel){
   
        return userService.showUserTel(tel);
    }
    public List<User> showUser(){
   
        return userService.showUser();
    }

    public boolean chickNUm(String num) {
   
        return userService.chickNUm(num);}
}

BanksDao

package com.vector.dao;

import com.vector.entity.Banks;
import com.vector.entity.User;
import com.vector.units.ConnectMsql;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class BanksDao {
   
    public boolean write(List<Banks> list){
   
        try {
   
        	String delsql = "delete from banks where bankNum = ?";
			String sql = "insert into banks(bankNum,money,bankName,tel) values(?,?,?,?)";
			Connection connection = ConnectMsql.getConnectMsql();
			PreparedStatement ad = connection.prepareStatement(sql);
			PreparedStatement del = connection.prepareStatement(delsql);
			int f=0;
			for(Banks user:list) {
   
				del.setString(1, user.getBankNumber());
				del.executeUpdate();
				ad.setString(1, user.getBankNumber());
				ad.setDouble(2, user.getMoney());
				ad.setString(3, user.getBankName());
				ad.setString(4, user.getTel());
				int i = ad.executeUpdate();
				if(i<0) {
   
				 System.out.println("添加失败!");
				 f++;
			     return false;
				}
			}
			if (f==0) {
   
				System.out.println("添加成功");
			}
        } catch (SQLException e) {
   
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
   
			ConnectMsql.closeConnection();
		}
		return true;
    }
    
    
    public List<Banks> read(){
   
    	List<Banks> list=new ArrayList<>();
		Connection connection = ConnectMsql.getConnectMsql();
		Statement stmt;
		try {
   
			stmt = connection.createStatement();
			ResultSet rs = stmt.executeQuery("select * from banks");
		while (rs.next()) {
   
			Banks bank =new Banks(rs.getString("bankNum"), rs.getDouble("money"), rs.getString("bankName"), rs.getString("tel"));
			list.add(bank);
		}
		} catch (SQLException e) {
   
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
   
			ConnectMsql.closeConnection();
		}
		 return list;
	}

    
}

RecordDao

package com.vector.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

import com.vector.entity.Banks;
import com.vector.entity.Record;
import com.vector.units.ConnectMsql;

public class RecordDao {
   
	public boolean write(List<Record> list) {
   
		LocalDateTime dateTime = LocalDateTime.now(); 
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");  
		String dataString=new String(dateTime.format(formatter));
		  try {
     	
			    String delsql = "delete from movemoney where id = ?";
				String sql = "insert into movemoney(outuser,inuser,money,date,id) values(?,?,?,?,?)";
				Connection connection = ConnectMsql.getConnectMsql();
				PreparedStatement ad = connection.prepareStatement(sql);
				PreparedStatement del = connection.prepareStatement(delsql);
				int f=0,k=1;
				for(Record record:list) {
   
					del.setInt(1, record.getId());
					del.executeUpdate();
					ad.setString(1, record.getOutuser());
					ad.setString(2, record.getInuser());
					ad.setDouble(3, record.getMoney());
					ad.setString(4,dataString);
					ad.setInt(5,k);
					int i = ad.executeUpdate();
					k++;
					if(i<0) {
   
					 System.out.println("添加失败!");
					 f++;
				     return false;
					}
				}
				if (f==0) {
   
					System.out.println("添加成功");
				}
	        } catch (SQLException e) {
   
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally {
   
				ConnectMsql.closeConnection();
			}
			return true;
	    }
	    
	    
	    public List<Record> read(){
   
	    	List<Record> list=new ArrayList<>();
			Connection connection = ConnectMsql.getConnectMsql();
			Statement stmt;
			try {
   
				stmt = connection.createStatement();
				ResultSet rs = stmt.executeQuery("select * from movemoney");
			while (rs.next()) {
   
				Record record =new Record(rs.getString("outuser"), rs.getString("inuser"),rs.getDouble("money"), rs.getString("date"),rs.getInt("id"));
				list.add(record);
			}
			} catch (SQLException e) {
   
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally {
   
				ConnectMsql.closeConnection();
			}
			 return list;
		}

}

UserDao

package com.vector.dao;

import java.util.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import javax.sound.midi.Soundbank;

import com.vector.entity.User;
import com.vector.units.ConnectMsql;

public class UserDao {
   
	public boolean write(List<User> list) {
   
		try {
   
			String delsql = "delete from user where tel = ?";
			String sql = "insert into user(name,cardNum,tel,pwd,email,money,relName) values(?,?,?,?,?,?,?)";
			Connection connection = ConnectMsql.getConnectMsql();
			PreparedStatement ad = connection.prepareStatement(sql);
			PreparedStatement del = connection.prepareStatement(delsql);
			int f=0;
			for(User user:list) {
   
				del.setString(1, user.getTel());
				del.executeUpdate();
				//System.out.println("这是密码"+user.getPwd());
				ad.setString(1, user.getName());
				ad.setString(2, user.getCardNum());
				ad.setString(3, user.getTel());
				ad.setString(4, user.getPwd());
				ad.setString(5, user.getEmail());
				ad.setDouble(6, user.getMoney());
				ad.setString(7, user.getRelName());
				int i = ad.executeUpdate();
				if(i<0) {
   
				 System.out.println("添加失败!");
				 f++;
			     return false;
				}
			}
			if (f==0) {
   
				System.out.println("添加成功");
			}
		} catch (SQLException e) {
   
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
   
			ConnectMsql.closeConnection();
		}
		return true;

	}
	public List<User> read() {
   
		List<User> list=new ArrayList<>();
		Connection connection = ConnectMsql.getConnectMsql();
		Statement stmt;
		try {
   
			stmt = connection.createStatement();
		ResultSet rs = stmt.executeQuery("select * from user");
		while (rs.next()) {
   
			User user=new User(rs.getString("name"), rs.getString("cardNum"), rs.getString("tel"),rs.getString("pwd"),rs.getString("email"), rs.getDouble("money"), rs.getString("relName"));
			list.add(user);
		}
		} catch (SQLException e) {
   
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
   
			ConnectMsql.closeConnection();
		}
		 return list;
	}
}

Banks

package com.vector.entity;

import javax.swing.*;
import java.io.Serializable;

public class Banks  {
   
    private String bankNumber;
    private double money;
    private String bankName;
    private String tel;

    public Banks(String bankNumber, double money, String bankName, String tel) {
   
        this.bankNumber = bankNumber;
        this.money = money;
        this.bankName = bankName;
        this.tel = tel;
    }

    public String getBankNumber() {
   
        return bankNumber;
    }

    public void setBankNumber(String bankNumber) {
   
        this.bankNumber = bankNumber;
    }

    public double getMoney() {
   
        return money;
    }

    public void setMoney(double money) {
   
        this.money = money;
    }

    public String getBankName() {
   
        return bankName;
    }

    public void setBankName(String bankName) {
   
        this.bankName = bankName;
    }

    public String getTel() {
   
        return tel;
    }

    public void setTel(String tel) {
   
        this.tel = tel;
    }

    @Override
    public String toString() {
   
        return "Banks{" +
                "bankNumber='" + bankNumber + '\'' +
                ", money=" + money +
                ", bankName='" + bankName + '\'' +
                ", tel='" + tel + '\'' +
                '}';
    }
}

Record

package com.vector.entity;

public class Record {
   
	private String outuser;
	private String inuser;
	private double money;
	private String date;
	private int id;
	public String getOutuser() {
   
		return outuser;
	}
	public void setOutuser(String outuser) {
   
		this.outuser = outuser;
	}
	public String getInuser() {
   
		return inuser;
	}
	public int getId() {
   
		return id;
	}
	public void setId(int id) {
   
		this.id = id;
	}
	public void setInuser(String inuser) {
   
		this.inuser = inuser;
	}
	public double getMoney() {
   
		return money;
	}
	public void setMoney(double money) {
   
		this.money = money;
	}
	public String getDate() {
   
		return date;
	}
	public void setDate(String date) {
   
		this.date = date;
	}
	
	
	public Record(String outuser, String inuser, double money, String date, int id) {
   
		super();
		this.outuser = outuser;
		this.inuser = inuser;
		this.money = money;
		this.date = date;
		this.id = id;
	}
	@Override
	public String toString() {
   
		return "Record [outuser=" + outuser + ", inuser=" + inuser + ", money=" + money + ", date=" + date + "]";
	}
}

User

package com.vector.entity;

import java.io.Serializable;

public class User  {
   
    private String name;
    private String cardNum;
    private String tel;
    private String pwd;
    private String email;
    private double money;
    private String relName;

    public String getName() {
   
        return name;
    }

    public void setName(String name) {
   
        this.name = name;
    }

    public String getCardNum() {
   
        return cardNum;
    }

    public void setCardNum(String cardNum) {
   
        this.cardNum = cardNum;
    }

    public String getTel() {
   
        return tel;
    }

    public void setTel(String tel) {
   
        this.tel = tel;
    }

    public String getPwd() {
   
        return pwd;
    }

    public void setPwd(String pwd) {
   
        this.pwd = pwd;
    }

    public String getEmail() {
   
        return email;
    }

    public void setEmail(String email) {
   
        this.email = email;
    }

    public double getMoney() {
   
        return money;
    }

    public void setMoney(double money) {
   
        this.money = money;
    }

    public String getRelName() {
   
        return relName;
    }

    public void setRelName(String relName) {
   
        this.relName = relName;
    }

    public User(String name, String cardNum, String tel, String pwd, String email, double money, String relName) {
   
        this.name = name;
        this.cardNum = cardNum;
        this.tel = tel;
        this.pwd = pwd;
        this.email = email;
        this.money = money;
        this.relName = relName;
    }

    public String toString() {
   
        return "User{" +
                "name='" + name + '\'' +
                ", cardNum='" + cardNum + '\'' +
                ", tel='" + tel + '\'' +
                ", pwd='" + pwd + '\'' +
                ", email='" + email + '\'' +
                ", money=
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

汤米先生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值