目录
一、系统功能
通过首页面进行 内容的选择
1、用户功能
a、用户注册登录
用户首先进行注册,然后再登陆进入用户首页面
b、用户完善自身信息,以及更改信息
用户第一次进入为添加自己的信息,再次进入,就是就行修改信息
c、用户捐赠图书
用户在捐赠图书时可以选择管理员早已设定好的图书类别
d、用户查询捐赠图书信息
用户查询自己捐赠的图书可以通过不同的方式来进行查询,以上是根据图书名进行的查询
2、管理员功能
管理员登陆时只有一个账户,没有进行添加功能
a、查看用户信息
管理员在查看用户信息时也可以根据不同的方法来进行查询,当前使用的利用用户姓名进行的查询
b、查看捐赠的图书信息
同样管理员在进行查询图书信息是也可以进行不同的方法查询
c、增加图书类别
二、系统部分代码展示
1、用户登录注册
public void login() {
System.out.println("**********欢迎使用用户图书管理系统**********");
Scanner sc = new Scanner(System.in);
System.out.print("请输入账号:");
String user = sc.next();
System.out.print("请输入密码:");
String password = sc.next();
Users myUser = this.userdao.selectLogin(user, password);
if (myUser != null) {
new InformationService().showMainMean(myUser.getId());
} else {
System.out.println("账号或密码错误!");
this.showNextMean();
}
}
2、用户完善信息
public void addInformation(String userId) {
Scanner sc = new Scanner(System.in);
Information infor = this.informationDao.selectAll(userId);
// 当已有用户信息时走以下流程
if (infor != null) {
System.out.println("姓名:" + infor.getName());
System.out.println("性别:" + infor.getSex());
System.out.println("电话:" + infor.getTel());
System.out.println("住址:" + infor.getAddress());
System.out.println("年龄:" + infor.getAge());
System.out.print("请问要修改信息吗(Y/N):");
String str = sc.next();
if ("Y".equalsIgnoreCase(str)) {
System.out.print("请输入姓名:");
String name = sc.next();
System.out.print("请输入性别:");
String sex = sc.next();
boolean flag;
String tel;
do {
flag = true;
System.out.print("请输入电话:");
tel = sc.next();
if (tel.length() != 11) {
flag = false;
System.out.println("电话输入有误,请重新输入!");
} else {
for (int i = 0; i < 11; i++) {
if (tel.charAt(i) < '0' || tel.charAt(i) > '9') {
flag = false;
System.out.println("电话输入有误,请重新输入!");
break;
}
}
}
} while (!flag);
System.out.print("请输入住址:");
String address = sc.next();
System.out.print("请输入年龄:");
int age = sc.nextInt();
String id = SqlUtil.getUUID();
Information infor1 = new Information(id, name, sex, tel, address, age, userId);
int num = this.informationDao.updateInformation(infor1);
if (num > 0) {
System.out.println("修改完成!");
} else {
System.out.println("修改失败!");
}
} else {
System.out.println("操作已取消!");
}
// 当没有用户信息时走下面流程
} else {
System.out.print("请输入姓名:");
String name = sc.next();
System.out.print("请输入性别:");
String sex = sc.next();
boolean flag;
String tel;
do {
flag = true;
System.out.print("请输入电话:");
tel = sc.next();
if (tel.length() != 11) {
flag = false;
System.out.println("电话输入有误,请重新输入!");
} else {
for (int i = 0; i < 11; i++) {
if (tel.charAt(i) < '0' || tel.charAt(i) > '9') {
flag = false;
System.out.println("电话输入有误,请重新输入!");
break;
}
}
}
} while (!flag);
System.out.print("请输入住址:");
String address = sc.next();
System.out.print("请输入年龄:");
int age = sc.nextInt();
String id = SqlUtil.getUUID();
Information infor1 = new Information(id, name, sex, tel, address, age, userId);
int num = this.informationDao.insertInformation(infor1);
if (num > 0) {
System.out.println("添加完成!");
} else {
System.out.println("添加失败!");
}
}
}
3、用户捐赠图书
public void addBook(String userId) {
Scanner sc = new Scanner(System.in);
Information infor = this.informationDao.selectAll(userId);
// 用户信息id
String informationId = infor.getId();
String id = SqlUtil.getUUID();
System.out.print("请输入图书名称:");
String bname = "《" + sc.next() + "》";
String uptime = DateUtil.DateToString(new Date(), "yyyy-MM-dd");
System.out.println("图书类别列表");
List<Category> list = this.categoryDao.selectAll();
System.out.println("\t编号\t\t\t\t类别名称");
for (Category iter : list) {
System.out.println(iter.getId() + "\t" + iter.getName());
}
String categoryId;
boolean flag;
do {
flag = true;
System.out.print("请输入图书编号:");
categoryId = sc.next();
for (Category iter : list) {
if (categoryId.equals(iter.getId())) {
// 找到了
flag = false;
break;
}
}
if (flag) {
System.out.println("输入有误,请重新输入!");
}
} while (flag);
Book book = new Book(id, bname, uptime, informationId, categoryId);
int num = this.bookDao.insertAll(book);
if (num > 0) {
System.out.println("捐赠成功!");
} else {
System.out.println("捐赠失败!");
}
}
4、用户查询图书,以书名为例
public void findBookByBname() {
Scanner sc = new Scanner(System.in);
System.out.print("输入要查询的书名:");
String bname = '《' + sc.next() + '》';
List<Map<String, Object>> list = this.bookDao.selectByBookName(bname);
if (list != null && !list.isEmpty()) {
System.out.println("书名\t\t捐赠时间\t\t图书类别\t捐赠人");
for (Map<String, Object> map : list) {
System.out.println(
map.get("bname") + "\t" + map.get("uptime") + "\t" + map.get("name") + "\t" + map.get("iname"));
}
} else {
System.out.println("没有该图书的信息!");
}
}
5、管理员查看用户信息,以姓名为例
public void findByName() {
Scanner sc = new Scanner(System.in);
System.out.print("输入要查询的姓名:");
String name = sc.next();
List<Information> list = this.informationDao.selectByName(name);
if (list != null && !list.isEmpty()) {
System.out.println("用户名\t性别\t电话\t\t住址\t年龄");
for (Information iter : list) {
System.out.println(iter.getName() + "\t" + iter.getSex() + "\t" + iter.getTel() + "\t"
+ iter.getAddress() + "\t" + iter.getAge());
}
} else {
System.out.println("没有该用户的信息!");
}
}
6、管理员查看图书信息,以书名为例
public void findBookByBname() {
Scanner sc = new Scanner(System.in);
System.out.print("输入要查询的书名:");
String bname = '《' + sc.next() + '》';
List<Map<String, Object>> list = this.bookDao.selectByBookName(bname);
if (list != null && !list.isEmpty()) {
System.out.println("书名\t\t捐赠时间\t\t图书类别\t捐赠人");
for (Map<String, Object> map : list) {
System.out.println(
map.get("bname") + "\t" + map.get("uptime") + "\t" + map.get("name") + "\t" + map.get("iname"));
}
} else {
System.out.println("没有该图书的信息!");
}
}
7、增加图书类别
public void insert() {
Scanner sc = new Scanner(System.in);
System.out.print("请输入类别名:");
String name = sc.next();
String id = SqlUtil.getUUID();
Category cate = new Category(id, name);
int num = this.category.insert(cate);
if (num > 0) {
System.out.println("增加成功!");
} else {
System.out.println("增加失败!");
}
}
三、数据库代码
/*
Navicat MySQL Data Transfer
Source Server : MySQL
Source Server Version : 50717
Source Host : localhost:3306
Source Database : book
Target Server Type : MYSQL
Target Server Version : 50717
File Encoding : 65001
Date: 2021-11-25 16:24:43
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `book`
-- ----------------------------
DROP TABLE IF EXISTS `book`;
CREATE TABLE `book` (
`id` varchar(50) NOT NULL,
`bname` varchar(50) DEFAULT NULL,
`uptime` date DEFAULT NULL,
`information_id` varchar(50) DEFAULT NULL,
`category_id` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `information_id` (`information_id`),
KEY `category_id` (`category_id`),
CONSTRAINT `book_ibfk_1` FOREIGN KEY (`information_id`) REFERENCES `information` (`id`),
CONSTRAINT `book_ibfk_2` FOREIGN KEY (`category_id`) REFERENCES `category` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of book
-- ----------------------------
INSERT INTO `book` VALUES ('2aec902913cd447f933ea7a7c45493cb', '《三国演义》', '2021-11-25', '308a1edf3da94ebcba2d01c471921af2', '2595136a10264cd79701492667ac1432');
INSERT INTO `book` VALUES ('ac106b3966a84057a46f456a65dbc56c', '《三十六计》', '2021-11-25', 'a5494dfa5409487a9666b7ab9a211916', '6954316192f7488c92342586bc2b57d9');
INSERT INTO `book` VALUES ('b3aa60a26bbe4f95b0de4ac2bd231000', '《时间简史》', '2021-11-25', '308a1edf3da94ebcba2d01c471921af2', '22517f40c21444069bedb4514176c947');
-- ----------------------------
-- Table structure for `category`
-- ----------------------------
DROP TABLE IF EXISTS `category`;
CREATE TABLE `category` (
`id` varchar(50) NOT NULL,
`name` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of category
-- ----------------------------
INSERT INTO `category` VALUES ('22517f40c21444069bedb4514176c947', '科学类');
INSERT INTO `category` VALUES ('2595136a10264cd79701492667ac1432', '历史类');
INSERT INTO `category` VALUES ('46a0169759304c67bb3cdf38def174f8', '武侠类');
INSERT INTO `category` VALUES ('6954316192f7488c92342586bc2b57d9', '军事类');
-- ----------------------------
-- Table structure for `information`
-- ----------------------------
DROP TABLE IF EXISTS `information`;
CREATE TABLE `information` (
`id` varchar(50) NOT NULL,
`name` varchar(50) DEFAULT NULL,
`sex` char(1) DEFAULT NULL,
`tel` varchar(11) DEFAULT NULL,
`address` varchar(100) DEFAULT NULL,
`age` int(11) DEFAULT NULL,
`users_id` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `users_id` (`users_id`),
KEY `name` (`name`),
CONSTRAINT `information_ibfk_1` FOREIGN KEY (`users_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of information
-- ----------------------------
INSERT INTO `information` VALUES ('308a1edf3da94ebcba2d01c471921af2', '张三', '男', '15194113877', '山东济南', '14', '20211125zhangsan');
INSERT INTO `information` VALUES ('a5494dfa5409487a9666b7ab9a211916', '李四', '女', '13216068852', '云南大理', '56', '20211125lisi');
-- ----------------------------
-- Table structure for `users`
-- ----------------------------
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`id` varchar(50) NOT NULL,
`user` varchar(10) DEFAULT NULL,
`password` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of users
-- ----------------------------
INSERT INTO `users` VALUES ('20211125lisi', 'lisi', '123456');
INSERT INTO `users` VALUES ('20211125zhangsan', 'zhangsan', '123456');
四、总结
这是自己第一次独立完成的java小程序,成就感特别满足.
总的来说呢,不足有很多,小细节有很多想象不到。
希望有大佬指正改错,因为使用的是一个小工具模板所以有些地方没法显示。