文章目录
- 前言
- 一. 功能
- 二. 代码
-
- 银行卡数据
- 转账流水数据
- 用户数据
- BanksController
- UserController
- BanksDao
- RecordDao
- UserDao
- Banks
- Record
- User
- BanksService 接口
- UserService接口
- BanksServiceImpl
- UsersServiceImpl
- AppStar 测试类
- ConnectMsql (JDBC连接Mysql数据库)
- AddBanksMoneyView
- AddBanksView
- AddUsersMoneyView
- AddUserView
- MainView
- MoveMoneyView
- ShowBanksView
- ShowMoveMoney
- ShowUserView
- UpdatePwdView
- UserLoginView
- UsersView
前言
银行用户管理系统是由我的另一篇博客项目 Java实训项目——网银管理系统改编而来。 与之不同的是,这个小项目新增了 转账流水功能, 并且运用了 集合,JavaSpring,Mysql数据库和JDBC。 虽然大同小异,但亦有可取之处。一. 功能
-
登陆
-
注册
-
首页
-
个人信息显示
-
修改密码
-
添加银行卡
-
银行卡查看
-
充值
-
提现
-
转账
-
用户管理
-
转账流水
把用户信息,银行卡信息和转账流水(包括充值,提现和转账)都存入数据库之中,在根据功能合理的使用这些数据。
详细的功能介绍在上一篇项目博客中已经介绍过了 ——网银管理系统。
二. 代码
银行卡数据
转账流水数据
用户数据
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=