package cn.hncu.bookStore.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
/**
* 用户的公用数据读取写入类
* @author 陈浩翔
*
* @version 1.0
*/
public class FileIoUtil {
public FileIoUtil() {
}
/**
* 从数据库中读取所有的数据并返回出来
*
* @param fileName(数据表对应的文件名字)
* @param ee(传递过来的泛型的类型!)
* @return 所有表的记录!
*/
@SuppressWarnings("unchecked")//压警告
public static<E> List<E> readFormFile(String fileName,E ee){
List<E> list = new ArrayList<E>();
final File file = new File(fileName);
ObjectInputStream in =null;
if(!file.exists()){
JOptionPane.showMessageDialog(null, "数据表不存在!");
return list;
}
try {
in = new ObjectInputStream(new FileInputStream(fileName));
try {
list = (List<E>) in.readObject();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
if(in!=null){
try {
in.close();
} catch (IOException e) {
throw new RuntimeException("数据库关闭失败");
}
}
}
return list;
}
/**
* 写入一个list集合进入数据文件fileName
*
* @param list(需要存储的数据集合)
* @param fileName(写入到哪个文件的文件名字)
*/
public static void write2file(List<Object> list, String fileName){
ObjectOutputStream out = null;
try {
out = new ObjectOutputStream(new FileOutputStream(fileName));
out.writeObject(list);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
if(out!=null){
try {
out.close();
} catch (IOException e) {
throw new RuntimeException("数据库关闭失败!");
}
}
}
}
}
package cn.hncu.bookStore.user.vo;
/**
* @author 陈浩翔
* @version 1.0
*
* <br/>
* 用于保存用户信息的值对象<br/>
* 1、可序列化<br/>
* 2、私有化所有变量成员,补setter-getters方法<br/>
* 3、写equals和hashCode方法----用主键(uuid)唯一标识码<br/>
* 4、toString方法<br/>
* 5,空参构造方法<br/>
*/
public class UserModel {
private String uuid;//用户唯一标识码
private String name;//用户名
private int type;//用户类型
private String pwd;//用户密码
public UserModel() {
}
/**
* 功能:得到uuid-用户唯一的标识码
*
* @return 返回uuid-用户唯一的标识码
*/
public String getUuid() {
return uuid;
}
/**
* 功能:设置uuid-用户唯一的标识码
* @param uuid-用户唯一的标识码-String型参数
*/
public void setUuid(String uuid) {
this.uuid = uuid;
}
/**
* 功能:得到用户的用户名
* @return---name-用户名
*/
public String getName() {
return name;
}
/**
* 功能:设置用户的用户名
*
* @param name--用户设置的用户名,String型参数
*/
public void setName(String name) {
this.name = name;
}
/**
* 功能:得到用户的类型:
* 1——表示为admin,可以进行全部操作
* 2——表示为能操作图书模块的人员
* 3——表示为能操作进货模块的人员
* 4——表示为能操作销售模块的人员
* 5——表示为能操作库存模块的人员
* @return 用户的类型
*/
public int getType() {
return type;
}
/**
* 功能:设置用户的类型:
* 1——表示为admin,可以进行全部操作
* 2——表示为能操作图书模块的人员
* 3——表示为能操作进货模块的人员
* 4——表示为能操作销售模块的人员
* 5——表示为能操作库存模块的人员
* @param type--用户的类型-int型参数
*/
public void setType(int type) {
this.type = type;
}
/**
*功能:得到用户的密码
* @return String型,用户的密码
*/
public String getPwd() {
return pwd;
}
/**
* 功能:设置用户的密码
* @param pwd--String型参数
*/
public void setPwd(String pwd) {
this.pwd = pwd;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
UserModel other = (UserModel) obj;
if (uuid == null) {
if (other.uuid != null)
return false;
} else if (!uuid.equals(other.uuid))
return false;
return true;
}
@Override
public String toString() {
return "UserModel [uuid=" + uuid + ", name=" + name + ", type=" + type
+ ", pwd=" + pwd + "]";
}
}
package cn.hncu.bookStore.user.vo;
public class UserQueryModel extends UserModel{
}
package cn.hncu.bookStore.user.dao.dao;
import java.util.List;
import cn.hncu.bookStore.user.vo.UserModel;
import cn.hncu.bookStore.user.vo.UserQueryModel;
/**
*
* @author 陈浩翔
*
* @version 1.0
* 用户模块的数据层接口
*/
public interface UserDao {
/**
* 功能:创建一个用户
*
* @param userModel---将要创建的用户数据
* @return---true表示创建成功,false表示创建失败
*/
public boolean create(UserModel user);
/**
* 功能:删除一个用户
*
* @param uuid---用户唯一的标识码,每个用户都不会相同
* @return---true表示删除成功,false表示删除失败
*/
public boolean delete(String uuid);
/**
* 功能:修改用户数据资料
*
* @param user---需要修改的用户数据参数名
* @return 返回true-表示修改成功了,返回false-表示修改失败
*/
public boolean update(UserModel user);
/**
* 功能:得到所有的用户数据
*
* @return---一个UserModel集合,也就是用户的数据
*/
public List<UserModel> getAll();
/**
* 功能:按照一定的查找条件进行查找,
* <br/>
* 把满足查找条件的用户数据返回。
*
* @param uqm---被封装的查找条件
* @return---满足查找条件的用户数据集合
*/
public List<UserModel> getbyCondition(UserQueryModel uqm);
/**
* 功能:得到一个确定的用户的数据资料
*
* @param uuid---用户唯一标识码
* @return ---返回按这个唯一标识码找到的用户数据
*/
public UserModel getSingle(String uuid);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2026 源码网商城 (www.ymwmall.com) 版权所有