Bug fixed,调整了项目结构。还有就是我恨DDL
This commit is contained in:
parent
3dc0a891fb
commit
f9c276e0ed
71
README.md
71
README.md
@ -1,56 +1,17 @@
|
||||
# Homework-entities
|
||||
*网安实训作业*
|
||||
# Homework
|
||||
- - -
|
||||
**Last Update Time : 2023-05-05**
|
||||
|
||||
# 2023-03-16
|
||||
- 初始化项目
|
||||
|
||||
# 2023-03-22
|
||||
- 增加实体类
|
||||
- 删除.idea文件
|
||||
|
||||
# 2023-03-26
|
||||
- 完善实体类
|
||||
- 我靠,折腾了一晚上,提交了十几次,终于提交时把.idea这个文件给忽略了
|
||||
- 方法:在`.gitgnore`文件中添加
|
||||
- `.idea/encodings.xml`
|
||||
- `.idea/misc.xml`
|
||||
- `.idea/vcs.xml`
|
||||
- `.idea/workspace.xml`
|
||||
- 然后在控制台输入`git rm -r --cached .idea`
|
||||
- 删除`gitee`或`github`上的`.idea`文件
|
||||
- `update`一下远端项目
|
||||
- `push`代码
|
||||
- 我好菜。。。
|
||||
|
||||
# 2023-03-27
|
||||
- 完善了一下实体类,发现商家那一部分漏了一点东西,给它补上了
|
||||
- 另外就是为什么`.idea`文件我已经取消提交了,为啥本地的`commit`里面还会有有啊……无语了
|
||||
- 是不是跟`git`八字不合。。。
|
||||
|
||||
# 2023-03-29
|
||||
- 添加`JDBC`驱动,连接数据库
|
||||
|
||||
# 2023-05-04
|
||||
- 创建数据库表,测试连接成功
|
||||
- 调整项目结构
|
||||
- 调整实体类与数据库对应的结构
|
||||
- 修改外键
|
||||
- 完成DAO层抽象接口
|
||||
- 完成MerchantsDAO和UserDAO具体功能
|
||||
|
||||
# 2023-05-05-NO.1
|
||||
- Bug fixed: MerchantsDAO 按ID查询功能
|
||||
- 搭建shellUI的大体框架
|
||||
- 完成UserDAO具体功能
|
||||
|
||||
# 2023-05-05-NO.2
|
||||
- 实现UserDAO和MerchantsDAO所有接口功能
|
||||
- shellUI完成
|
||||
- 测试
|
||||
- UserDAO和MerchantsDAO的增加、查询、删除功能测试通过
|
||||
- shellUI功能测试通过
|
||||
- Bug Fixed
|
||||
- DAO层Merchants、User类查询问题
|
||||
- 按ID查询报错
|
||||
- 全部查询只显示最后添加的行
|
||||
- 输出格式混乱问题
|
||||
日志文件:`log.md`
|
||||
- - -
|
||||
### 运行方式:
|
||||
```text
|
||||
src -> main -> java -> example -> App.run()
|
||||
```
|
||||
### 待修复bug
|
||||
- `userDAO`和`merchantsDAO`中`update`语句未传参
|
||||
- 未测试非法数据
|
||||
### 待完成功能
|
||||
- `indentDAO`和`indentItemDAO`方法实现
|
||||
- 联合查询
|
||||
- `updata`方法更新指定字段
|
67
log.md
Normal file
67
log.md
Normal file
@ -0,0 +1,67 @@
|
||||
# Homework
|
||||
|
||||
*网安实训作业*
|
||||
|
||||
## 2023-05-05-NO.2
|
||||
|
||||
- 实现UserDAO和MerchantsDAO所有接口功能
|
||||
- shellUI完成
|
||||
- 测试
|
||||
- UserDAO和MerchantsDAO的增加、查询、删除功能测试通过
|
||||
- shellUI功能测试通过
|
||||
- Bug Fixed
|
||||
- DAO层Merchants、User类查询问题
|
||||
- 按ID查询报错
|
||||
- 全部查询只显示最后添加的行
|
||||
- 输出格式混乱问题
|
||||
- 我恨DDL
|
||||
|
||||
## 2023-05-05-NO.1
|
||||
|
||||
- Bug fixed: MerchantsDAO 按ID查询功能
|
||||
- 搭建shellUI的大体框架
|
||||
- 完成UserDAO具体功能
|
||||
|
||||
## 2023-05-04
|
||||
|
||||
- 创建数据库表,测试连接成功
|
||||
- 调整项目结构
|
||||
- 调整实体类与数据库对应的结构
|
||||
- 修改外键
|
||||
- 完成DAO层抽象接口
|
||||
- 完成MerchantsDAO和UserDAO具体功能
|
||||
-
|
||||
|
||||
## 2023-03-29
|
||||
|
||||
- 添加`JDBC`驱动,连接数据库
|
||||
|
||||
## 2023-03-27
|
||||
|
||||
- 完善了一下实体类,发现商家那一部分漏了一点东西,给它补上了
|
||||
- 另外就是为什么`.idea`文件我已经取消提交了,为啥本地的`commit`里面还会有有啊……无语了
|
||||
- 是不是跟`git`八字不合。。。
|
||||
|
||||
## 2023-03-26
|
||||
|
||||
- 完善实体类
|
||||
- 我靠,折腾了一晚上,提交了十几次,终于提交时把.idea这个文件给忽略了
|
||||
- 方法:在`.gitgnore`文件中添加
|
||||
- `.idea/encodings.xml`
|
||||
- `.idea/misc.xml`
|
||||
- `.idea/vcs.xml`
|
||||
- `.idea/workspace.xml`
|
||||
- 然后在控制台输入`git rm -r --cached .idea`
|
||||
- 删除`gitee`或`github`上的`.idea`文件
|
||||
- `update`一下远端项目
|
||||
- `push`代码
|
||||
- 我好菜。。。
|
||||
|
||||
## 2023-03-22
|
||||
|
||||
- 增加实体类
|
||||
- 删除.idea文件
|
||||
|
||||
## 2023-03-16
|
||||
|
||||
- 初始化项目
|
@ -1,4 +1,7 @@
|
||||
package dao;
|
||||
|
||||
public interface IndentAbstractDAO {
|
||||
import entities.Indent;
|
||||
|
||||
public interface IndentAbstractDAO extends abstractDAO<Indent> {
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,5 @@
|
||||
package dao.specification;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
//@TODO 重构代码 合并userDAO和merchantsDAO中重复方法
|
||||
public class abstractDAO {
|
||||
|
||||
public class abstractDAO<T> {
|
||||
}
|
||||
|
34
src/main/java/dao/specification/indentDAO.java
Normal file
34
src/main/java/dao/specification/indentDAO.java
Normal file
@ -0,0 +1,34 @@
|
||||
package dao.specification;
|
||||
|
||||
import dao.IndentAbstractDAO;
|
||||
import entities.Indent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class indentDAO implements IndentAbstractDAO {
|
||||
|
||||
@Override
|
||||
public int insert(Indent indent) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(Indent indent) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(Indent indent) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Indent> search(Indent indent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Indent searchID(Long id) {
|
||||
return null;
|
||||
}
|
||||
}
|
4
src/main/java/dao/specification/indentItemDAO.java
Normal file
4
src/main/java/dao/specification/indentItemDAO.java
Normal file
@ -0,0 +1,4 @@
|
||||
package dao.specification;
|
||||
|
||||
public class indentItemDAO {
|
||||
}
|
@ -60,6 +60,7 @@ public class merchantsDAO implements merchantsAbstractDAO {
|
||||
}
|
||||
|
||||
//更新信息
|
||||
//@TODO 只能更新所有信息,不能选择性更新
|
||||
@Override
|
||||
public int update(@NotNull Merchants merchants) {
|
||||
int flag;
|
||||
|
@ -64,6 +64,7 @@ public class userDAO implements userAbstractDAO {
|
||||
}
|
||||
|
||||
//更新用户个人信息
|
||||
//@TODO 只能更新所有信息,不能选择性更新
|
||||
@Override
|
||||
public int update(@NotNull Users users) {
|
||||
int flag;
|
||||
@ -101,10 +102,11 @@ public class userDAO implements userAbstractDAO {
|
||||
|
||||
while (resultSet.next()) {
|
||||
users = new Users();
|
||||
users.setName(resultSet.getString("id"));
|
||||
users.setId(resultSet.getLong("id"));
|
||||
users.setName(resultSet.getString("name"));
|
||||
users.setPhoneNumber(resultSet.getString("phoneNumber"));
|
||||
users.setAddress(resultSet.getString("address"));
|
||||
users.setPassword(resultSet.getString("password"));
|
||||
list.add(users);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
|
@ -9,10 +9,10 @@ import java.util.Date;
|
||||
public class Indent {
|
||||
private Long id;//订单ID
|
||||
|
||||
private Users userID;//外键,下单用户ID
|
||||
private Merchants merchantsID;//外键,餐厅ID
|
||||
|
||||
private Float allPrice;//菜品总价
|
||||
Date createdDate;//订单创建时间
|
||||
String message;//下单备注
|
||||
|
||||
private Users userID;//外键,下单用户ID
|
||||
private Merchants merchantsID;//外键,餐厅ID
|
||||
}
|
||||
|
@ -11,5 +11,5 @@ public class indentItem {
|
||||
private Float finalPrice;//最终价格
|
||||
private String description;//菜品描述
|
||||
|
||||
private Indent indentID;//订单ID
|
||||
private Indent indentID;//外键,订单ID
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
package example;
|
||||
|
||||
import entities.*;
|
||||
import static view.shellUI.run;
|
||||
|
||||
public class App {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("你好世界!Hello World!");
|
||||
public static void main(String[] args) throws IllegalAccessException {
|
||||
run();
|
||||
}
|
||||
}
|
||||
|
@ -1,157 +0,0 @@
|
||||
package example;
|
||||
|
||||
import dao.merchantsAbstractDAO;
|
||||
import dao.specification.merchantsDAO;
|
||||
import dao.specification.userDAO;
|
||||
import dao.userAbstractDAO;
|
||||
import entities.Merchants;
|
||||
import entities.Users;
|
||||
import util.Toolset;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class shellUI {
|
||||
public static void main(String[] args) throws IllegalAccessException {
|
||||
run();
|
||||
}
|
||||
|
||||
public static void run() throws IllegalAccessException {
|
||||
|
||||
System.out.println("""
|
||||
------------------------------------------
|
||||
----------------后台管理系统----------------
|
||||
------------------------------------------
|
||||
""");
|
||||
Chose();
|
||||
}
|
||||
|
||||
//选项一
|
||||
private static void Chose() throws IllegalAccessException {
|
||||
System.out.println("""
|
||||
请选择你要进行的功能:
|
||||
1.商家管理\t2.用户管理\t0.退出
|
||||
""");
|
||||
|
||||
switch (Toolset.option()) {
|
||||
case 0 -> System.exit(0);
|
||||
//商家
|
||||
case 1 -> {
|
||||
System.out.println("""
|
||||
请选择你想使用的功能:
|
||||
1.新建商家\t\t2.删除商家\t\t3.更新信息
|
||||
4.查询所有商家\t5.根据ID查询商家\t0.退出
|
||||
""");
|
||||
merchantsDB(Toolset.option());
|
||||
Chose();
|
||||
}
|
||||
//用户
|
||||
case 2 -> {
|
||||
System.out.println("""
|
||||
请选择你想使用的功能:
|
||||
1.新建用户\t\t2.删除用户\t\t3.更新信息
|
||||
4.查询所有用户\t5.根据ID查询用户\t0.退出
|
||||
""");
|
||||
userDB(Toolset.option());
|
||||
Chose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//商家数据库操作
|
||||
private static void merchantsDB(int chose) throws IllegalAccessException {
|
||||
int flag;
|
||||
Merchants merchants;
|
||||
Scanner reader = new Scanner(System.in);
|
||||
switch (chose) {
|
||||
case 0 -> System.exit(0);
|
||||
case 1 -> {//@TODO 输入格式化 不换行
|
||||
merchantsAbstractDAO DML_insert = new merchantsDAO();
|
||||
System.out.println("请输入:店铺名字|地址|描述|电话");
|
||||
merchants = new Merchants(reader.nextLine(), reader.nextLine(), reader.nextLine(), reader.nextLine());
|
||||
flag = DML_insert.insert(merchants);
|
||||
System.out.println(flag + "行受影响");
|
||||
}
|
||||
case 2 -> {
|
||||
merchantsAbstractDAO DML_delete = new merchantsDAO();
|
||||
merchants = new Merchants();
|
||||
|
||||
System.out.println("请输入你要删除商家的ID");
|
||||
merchants.setId(reader.nextLong());
|
||||
|
||||
flag = DML_delete.delete(merchants);
|
||||
System.out.println(flag + "行受影响");
|
||||
}
|
||||
case 3 -> {
|
||||
merchantsAbstractDAO DML_update = new merchantsDAO();
|
||||
merchants = new Merchants();
|
||||
flag = DML_update.update(merchants);
|
||||
System.out.println(flag + "行受影响");
|
||||
}
|
||||
case 4 -> {
|
||||
merchantsAbstractDAO DQL_all = new merchantsDAO();
|
||||
merchants = new Merchants();
|
||||
//格式化输出
|
||||
for (Merchants item : DQL_all.search(merchants)) {
|
||||
System.out.println(Toolset.table(Merchants.class, item));
|
||||
}
|
||||
|
||||
}
|
||||
case 5 -> {
|
||||
merchantsAbstractDAO DQL_ID = new merchantsDAO();
|
||||
new Merchants();
|
||||
System.out.println("请输入你要查询的ID:");
|
||||
merchants = DQL_ID.searchID(reader.nextLong());
|
||||
//格式化输出
|
||||
System.out.println(Toolset.table(Merchants.class, merchants));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//用户数据库操作
|
||||
private static void userDB(int chose) throws IllegalAccessException {
|
||||
int flag;
|
||||
Users user;
|
||||
Scanner reader = new Scanner(System.in);
|
||||
|
||||
switch (chose) {
|
||||
case 0 -> System.exit(0);
|
||||
case 1 -> {//@TODO 非换行输入
|
||||
userAbstractDAO DML_insert = new userDAO();
|
||||
System.out.println("请输入:名字|电话|地址|密码");
|
||||
user = new Users(reader.nextLine(), reader.nextLine(), reader.nextLine(), reader.nextLine());
|
||||
flag = DML_insert.insert(user);
|
||||
System.out.println(flag + "行受影响");
|
||||
}
|
||||
case 2 -> {
|
||||
userAbstractDAO DML_delete = new userDAO();
|
||||
user = new Users();
|
||||
flag = DML_delete.delete(user);
|
||||
System.out.println(flag + "行受影响");
|
||||
}
|
||||
case 3 -> {
|
||||
userAbstractDAO DML_update = new userDAO();
|
||||
user = new Users();
|
||||
flag = DML_update.update(user);
|
||||
System.out.println(flag + "行受影响");
|
||||
}
|
||||
case 4 -> {
|
||||
userAbstractDAO DQL_all = new userDAO();
|
||||
user = new Users();
|
||||
//格式化输出
|
||||
for (Users item : DQL_all.search(user)) {
|
||||
System.out.println(Toolset.table(Users.class, item));
|
||||
}
|
||||
|
||||
}
|
||||
case 5 -> {
|
||||
userAbstractDAO DQL_ID = new userDAO();
|
||||
new Users();
|
||||
System.out.println("请输入你要查询的ID:");
|
||||
user = DQL_ID.searchID(reader.nextLong());
|
||||
//格式化输出
|
||||
System.out.println(Toolset.table(Users.class, user));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -27,16 +27,16 @@ public class SQLDatabaseConnection {
|
||||
}
|
||||
|
||||
//释放资源
|
||||
public static void close(Connection connection, Statement statement, ResultSet resultSet) {
|
||||
public static void close(Connection conn, Statement st, ResultSet rs) {
|
||||
try {
|
||||
if (resultSet != null) {
|
||||
resultSet.close();
|
||||
if (rs != null) {
|
||||
rs.close();
|
||||
}
|
||||
if (statement != null) {
|
||||
statement.close();
|
||||
if (st != null) {
|
||||
st.close();
|
||||
}
|
||||
if (connection != null) {
|
||||
connection.close();
|
||||
if (conn != null) {
|
||||
conn.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
61
src/main/java/view/MerchantsView.java
Normal file
61
src/main/java/view/MerchantsView.java
Normal file
@ -0,0 +1,61 @@
|
||||
package view;
|
||||
|
||||
import dao.merchantsAbstractDAO;
|
||||
import dao.specification.merchantsDAO;
|
||||
import entities.Merchants;
|
||||
import util.Toolset;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class MerchantsView {
|
||||
//商家数据库操作
|
||||
protected static void merchantsDB(int chose) throws IllegalAccessException {
|
||||
int flag;
|
||||
Merchants merchants;
|
||||
Scanner reader = new Scanner(System.in);
|
||||
switch (chose) {
|
||||
case 0 -> System.exit(0);
|
||||
case 1 -> {//@TODO 输入格式化 不换行
|
||||
merchantsAbstractDAO DML_insert = new merchantsDAO();
|
||||
System.out.println("请输入:店铺名字|地址|描述|电话");
|
||||
merchants = new Merchants(reader.nextLine(), reader.nextLine(), reader.nextLine(), reader.nextLine());
|
||||
flag = DML_insert.insert(merchants);
|
||||
System.out.println(flag + "行受影响");
|
||||
}
|
||||
case 2 -> {
|
||||
merchantsAbstractDAO DML_delete = new merchantsDAO();
|
||||
merchants = new Merchants();
|
||||
|
||||
System.out.println("请输入你要删除的ID");
|
||||
merchants.setId(reader.nextLong());
|
||||
|
||||
flag = DML_delete.delete(merchants);
|
||||
System.out.println(flag + "行受影响");
|
||||
}
|
||||
case 3 -> {//@FIXME update没有传值
|
||||
merchantsAbstractDAO DML_update = new merchantsDAO();
|
||||
merchants = new Merchants();
|
||||
flag = DML_update.update(merchants);
|
||||
System.out.println(flag + "行受影响");
|
||||
}
|
||||
case 4 -> {
|
||||
merchantsAbstractDAO DQL_all = new merchantsDAO();
|
||||
merchants = new Merchants();
|
||||
//格式化输出
|
||||
for (Merchants item : DQL_all.search(merchants)) {
|
||||
System.out.println(Toolset.table(Merchants.class, item));
|
||||
}
|
||||
|
||||
}
|
||||
case 5 -> {
|
||||
merchantsAbstractDAO DQL_ID = new merchantsDAO();
|
||||
new Merchants();
|
||||
System.out.println("请输入你要查询的ID:");
|
||||
merchants = DQL_ID.searchID(reader.nextLong());
|
||||
//格式化输出
|
||||
System.out.println(Toolset.table(Merchants.class, merchants));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
61
src/main/java/view/UserView.java
Normal file
61
src/main/java/view/UserView.java
Normal file
@ -0,0 +1,61 @@
|
||||
package view;
|
||||
|
||||
import dao.specification.userDAO;
|
||||
import dao.userAbstractDAO;
|
||||
import entities.Users;
|
||||
import util.Toolset;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class UserView {
|
||||
//用户数据库操作
|
||||
protected static void userDB(int chose) throws IllegalAccessException {
|
||||
int flag;
|
||||
Users user;
|
||||
Scanner reader = new Scanner(System.in);
|
||||
|
||||
switch (chose) {
|
||||
case 0 -> System.exit(0);
|
||||
case 1 -> {//@TODO 非换行输入
|
||||
userAbstractDAO DML_insert = new userDAO();
|
||||
System.out.println("请输入:名字|电话|地址|密码");
|
||||
user = new Users(reader.nextLine(), reader.nextLine(), reader.nextLine(), reader.nextLine());
|
||||
flag = DML_insert.insert(user);
|
||||
System.out.println(flag + "行受影响");
|
||||
}
|
||||
case 2 -> {
|
||||
userAbstractDAO DML_delete = new userDAO();
|
||||
user = new Users();
|
||||
|
||||
System.out.println("请输入你要删除的ID:");
|
||||
user.setId(reader.nextLong());
|
||||
flag = DML_delete.delete(user);
|
||||
|
||||
System.out.println(flag + "行受影响");
|
||||
}
|
||||
case 3 -> {//@FIXME update没有传值
|
||||
userAbstractDAO DML_update = new userDAO();
|
||||
user = new Users();
|
||||
flag = DML_update.update(user);
|
||||
System.out.println(flag + "行受影响");
|
||||
}
|
||||
case 4 -> {
|
||||
userAbstractDAO DQL_all = new userDAO();
|
||||
user = new Users();
|
||||
//格式化输出
|
||||
for (Users item : DQL_all.search(user)) {
|
||||
System.out.println(Toolset.table(Users.class, item));
|
||||
}
|
||||
|
||||
}
|
||||
case 5 -> {
|
||||
userAbstractDAO DQL_ID = new userDAO();
|
||||
new Users();
|
||||
System.out.println("请输入你要查询的ID:");
|
||||
user = DQL_ID.searchID(reader.nextLong());
|
||||
//格式化输出
|
||||
System.out.println(Toolset.table(Users.class, user));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
51
src/main/java/view/shellUI.java
Normal file
51
src/main/java/view/shellUI.java
Normal file
@ -0,0 +1,51 @@
|
||||
package view;
|
||||
|
||||
import util.Toolset;
|
||||
|
||||
import static view.MerchantsView.merchantsDB;
|
||||
import static view.UserView.userDB;
|
||||
|
||||
public class shellUI {
|
||||
public static void run() throws IllegalAccessException {
|
||||
|
||||
System.out.println("""
|
||||
------------------------------------------
|
||||
-----------------后台管理系统---------------
|
||||
------------------------------------------
|
||||
""");
|
||||
Chose();
|
||||
}
|
||||
|
||||
//选项一
|
||||
private static void Chose() throws IllegalAccessException {
|
||||
System.out.println("""
|
||||
请选择你要进行的功能:
|
||||
1.商家管理\t2.用户管理\t0.退出
|
||||
""");
|
||||
|
||||
switch (Toolset.option()) {
|
||||
case 0 -> System.exit(0);
|
||||
//商家
|
||||
case 1 -> {
|
||||
System.out.println("""
|
||||
请选择你想使用的功能:
|
||||
1.新建商家\t\t2.删除商家\t\t3.更新信息
|
||||
4.查询所有商家\t5.根据ID查询商家\t0.退出
|
||||
""");
|
||||
merchantsDB(Toolset.option());
|
||||
Chose();
|
||||
}
|
||||
//用户
|
||||
case 2 -> {
|
||||
System.out.println("""
|
||||
请选择你想使用的功能:
|
||||
1.新建用户\t\t2.删除用户\t\t3.更新信息
|
||||
4.查询所有用户\t5.根据ID查询用户\t0.退出
|
||||
""");
|
||||
userDB(Toolset.option());
|
||||
Chose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user