01河北金立公文系统开发
因为开学老师会直接测试这个内容,而自己还不是很会,所以想要提前做一下试一试,自己什么东西没学好,只能试着做一做,走一步看一步。
因为我要用springboot来做,所以今天刚刚搭建好环境和确定了数据库,不知道对不对,只能先做着用。
实体类
1 以下是使用Java编写的每个表的实体类代码。每个类都对应一个数据库表,并包含表中的字段及其对应的getter和setter方法。 2 3 ### 1. **Roles 实体类** 4 5 ```java 6 public class Role { 7 private int roleId; 8 private String roleName; 9 10 // Constructor 11 public Role() {} 12 13 public Role(int roleId, String roleName) { 14 this.roleId = roleId; 15 this.roleName = roleName; 16 } 17 18 // Getters and Setters 19 public int getRoleId() { 20 return roleId; 21 } 22 23 public void setRoleId(int roleId) { 24 this.roleId = roleId; 25 } 26 27 public String getRoleName() { 28 return roleName; 29 } 30 31 public void setRoleName(String roleName) { 32 this.roleName = roleName; 33 } 34 } 35 ``` 36 37 ### 2. **Departments 实体类** 38 39 ```java 40 public class Department { 41 private int departmentId; 42 private String departmentName; 43 44 // Constructor 45 public Department() {} 46 47 public Department(int departmentId, String departmentName) { 48 this.departmentId = departmentId; 49 this.departmentName = departmentName; 50 } 51 52 // Getters and Setters 53 public int getDepartmentId() { 54 return departmentId; 55 } 56 57 public void setDepartmentId(int departmentId) { 58 this.departmentId = departmentId; 59 } 60 61 public String getDepartmentName() { 62 return departmentName; 63 } 64 65 public void setDepartmentName(String departmentName) { 66 this.departmentName = departmentName; 67 } 68 } 69 ``` 70 71 ### 3. **Users 实体类** 72 73 ```java 74 public class User { 75 private int userId; 76 private String username; 77 private String passwordHash; 78 private int roleId; 79 private int departmentId; 80 private String email; 81 82 // Constructor 83 public User() {} 84 85 public User(int userId, String username, String passwordHash, int roleId, int departmentId, String email) { 86 this.userId = userId; 87 this.username = username; 88 this.passwordHash = passwordHash; 89 this.roleId = roleId; 90 this.departmentId = departmentId; 91 this.email = email; 92 } 93 94 // Getters and Setters 95 public int getUserId() { 96 return userId; 97 } 98 99 public void setUserId(int userId) { 100 this.userId = userId; 101 } 102 103 public String getUsername() { 104 return username; 105 } 106 107 public void setUsername(String username) { 108 this.username = username; 109 } 110 111 public String getPasswordHash() { 112 return passwordHash; 113 } 114 115 public void setPasswordHash(String passwordHash) { 116 this.passwordHash = passwordHash; 117 } 118 119 public int getRoleId() { 120 return roleId; 121 } 122 123 public void setRoleId(int roleId) { 124 this.roleId = roleId; 125 } 126 127 public int getDepartmentId() { 128 return departmentId; 129 } 130 131 public void setDepartmentId(int departmentId) { 132 this.departmentId = departmentId; 133 } 134 135 public String getEmail() { 136 return email; 137 } 138 139 public void setEmail(String email) { 140 this.email = email; 141 } 142 } 143 ``` 144 145 ### 4. **Documents 实体类** 146 147 ```java 148 import java.util.Date; 149 150 public class Document { 151 private int documentId; 152 private String title; 153 private String content; 154 private String status; 155 private String reviewStatus; 156 private int createdBy; 157 private Date createdAt; 158 private Date updatedAt; 159 160 // Constructor 161 public Document() {} 162 163 public Document(int documentId, String title, String content, String status, String reviewStatus, int createdBy, Date createdAt, Date updatedAt) { 164 this.documentId = documentId; 165 this.title = title; 166 this.content = content; 167 this.status = status; 168 this.reviewStatus = reviewStatus; 169 this.createdBy = createdBy; 170 this.createdAt = createdAt; 171 this.updatedAt = updatedAt; 172 } 173 174 // Getters and Setters 175 public int getDocumentId() { 176 return documentId; 177 } 178 179 public void setDocumentId(int documentId) { 180 this.documentId = documentId; 181 } 182 183 public String getTitle() { 184 return title; 185 } 186 187 public void setTitle(String title) { 188 this.title = title; 189 } 190 191 public String getContent() { 192 return content; 193 } 194 195 public void setContent(String content) { 196 this.content = content; 197 } 198 199 public String getStatus() { 200 return status; 201 } 202 203 public void setStatus(String status) { 204 this.status = status; 205 } 206 207 public String getReviewStatus() { 208 return reviewStatus; 209 } 210 211 public void setReviewStatus(String reviewStatus) { 212 this.reviewStatus = reviewStatus; 213 } 214 215 public int getCreatedBy() { 216 return createdBy; 217 } 218 219 public void setCreatedBy(int createdBy) { 220 this.createdBy = createdBy; 221 } 222 223 public Date getCreatedAt() { 224 return createdAt; 225 } 226 227 public void setCreatedAt(Date createdAt) { 228 this.createdAt = createdAt; 229 } 230 231 public Date getUpdatedAt() { 232 return updatedAt; 233 } 234 235 public void setUpdatedAt(Date updatedAt) { 236 this.updatedAt = updatedAt; 237 } 238 } 239 ``` 240 241 ### 5. **Document_Flow 实体类** 242 243 ```java 244 import java.util.Date; 245 246 public class DocumentFlow { 247 private int flowId; 248 private int documentId; 249 private int fromUserId; 250 private int toUserId; 251 private String action; 252 private String comments; 253 private Date actionTime; 254 255 // Constructor 256 public DocumentFlow() {} 257 258 public DocumentFlow(int flowId, int documentId, int fromUserId, int toUserId, String action, String comments, Date actionTime) { 259 this.flowId = flowId; 260 this.documentId = documentId; 261 this.fromUserId = fromUserId; 262 this.toUserId = toUserId; 263 this.action = action; 264 this.comments = comments; 265 this.actionTime = actionTime; 266 } 267 268 // Getters and Setters 269 public int getFlowId() { 270 return flowId; 271 } 272 273 public void setFlowId(int flowId) { 274 this.flowId = flowId; 275 } 276 277 public int getDocumentId() { 278 return documentId; 279 } 280 281 public void setDocumentId(int documentId) { 282 this.documentId = documentId; 283 } 284 285 public int getFromUserId() { 286 return fromUserId; 287 } 288 289 public void setFromUserId(int fromUserId) { 290 this.fromUserId = fromUserId; 291 } 292 293 public int getToUserId() { 294 return toUserId; 295 } 296 297 public void setToUserId(int toUserId) { 298 this.toUserId = toUserId; 299 } 300 301 public String getAction() { 302 return action; 303 } 304 305 public void setAction(String action) { 306 this.action = action; 307 } 308 309 public String getComments() { 310 return comments; 311 } 312 313 public void setComments(String comments) { 314 this.comments = comments; 315 } 316 317 public Date getActionTime() { 318 return actionTime; 319 } 320 321 public void setActionTime(Date actionTime) { 322 this.actionTime = actionTime; 323 } 324 } 325 ``` 326 327 ### **总结** 328 329 这些实体类与数据库中的表结构一一对应,并且每个类都包含了基本的构造函数、getter 和 setter 方法。这些类可以用作Java应用程序中的数据模型,用来与数据库进行交互。
建表语句
1 这个错误提示意味着在创建 `Users` 表时,数据库找不到 `Roles` 表。这通常是因为 `Roles` 表还没有创建,或者创建顺序有问题。确保在创建 `Users` 表之前已经成功创建了 `Roles` 和 `Departments` 表。 2 3 以下是正确的创建顺序: 4 5 1. **先创建 `Roles` 表和 `Departments` 表**: 6 7 ```sql 8 CREATE TABLE Roles ( 9 role_id INT AUTO_INCREMENT PRIMARY KEY, 10 role_name VARCHAR(50) NOT NULL 11 ); 12 13 CREATE TABLE Departments ( 14 department_id INT AUTO_INCREMENT PRIMARY KEY, 15 department_name VARCHAR(100) NOT NULL 16 ); 17 ``` 18 19 2. **然后创建 `Users` 表**: 20 21 ```sql 22 CREATE TABLE Users ( 23 user_id INT AUTO_INCREMENT PRIMARY KEY, 24 username VARCHAR(50) UNIQUE NOT NULL, 25 password_hash VARCHAR(255) NOT NULL, 26 role_id INT NOT NULL, 27 department_id INT NOT NULL, 28 email VARCHAR(100), 29 FOREIGN KEY (role_id) REFERENCES Roles(role_id), 30 FOREIGN KEY (department_id) REFERENCES Departments(department_id) 31 ); 32 ``` 33 34 3. **接着创建 `Documents` 表**: 35 36 ```sql 37 CREATE TABLE Documents ( 38 document_id INT AUTO_INCREMENT PRIMARY KEY, 39 title VARCHAR(255) NOT NULL, 40 content TEXT NOT NULL, 41 status VARCHAR(50) NOT NULL, 42 review_status VARCHAR(50) DEFAULT '待审核', 43 created_by INT NOT NULL, 44 created_at DATETIME DEFAULT CURRENT_TIMESTAMP, 45 updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 46 FOREIGN KEY (created_by) REFERENCES Users(user_id) 47 ); 48 ``` 49 50 4. **最后创建 `Document_Flow` 表**: 51 52 ```sql 53 CREATE TABLE Document_Flow ( 54 flow_id INT AUTO_INCREMENT PRIMARY KEY, 55 document_id INT NOT NULL, 56 from_user_id INT NOT NULL, 57 to_user_id INT NOT NULL, 58 action VARCHAR(50) NOT NULL, 59 comments TEXT, 60 action_time DATETIME DEFAULT CURRENT_TIMESTAMP, 61 FOREIGN KEY (document_id) REFERENCES Documents(document_id), 62 FOREIGN KEY (from_user_id) REFERENCES Users(user_id), 63 FOREIGN KEY (to_user_id) REFERENCES Users(user_id) 64 ); 65 ``` 66 67 按照这个顺序执行 SQL 语句,可以确保所有的外键引用正确。
明天的话试着完成注册和登录接口。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?