完成Day2
This commit is contained in:
commit
2e741987bf
6
.idea/1
generated
Normal file
6
.idea/1
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
10
.idea/libraries/lib.xml
generated
Normal file
10
.idea/libraries/lib.xml
generated
Normal file
@ -0,0 +1,10 @@
|
||||
<component name="libraryTable">
|
||||
<library name="lib">
|
||||
<CLASSES>
|
||||
<root url="file://$PROJECT_DIR$/lib" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
<jarDirectory url="file://$PROJECT_DIR$/lib" recursive="false" />
|
||||
</library>
|
||||
</component>
|
6
.idea/misc.xml
generated
Normal file
6
.idea/misc.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/AbsenceManager.iml" filepath="$PROJECT_DIR$/AbsenceManager.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
99
.idea/workspace.xml
generated
Normal file
99
.idea/workspace.xml
generated
Normal file
@ -0,0 +1,99 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="a16f9e6c-d3d8-4ed4-a07c-f75cc82e9a65" name="默认更改列表" comment="" />
|
||||
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="FileTemplateManagerImpl">
|
||||
<option name="RECENT_TEMPLATES">
|
||||
<list>
|
||||
<option value="Class" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectId" id="2qKehD6GdgWuPyMkIr2rZ4Mbypj" />
|
||||
<component name="PropertiesComponent">
|
||||
<property name="WebServerToolWindowFactoryState" value="false" />
|
||||
<property name="aspect.path.notification.shown" value="true" />
|
||||
<property name="last_opened_file_path" value="$PROJECT_DIR$/lib" />
|
||||
</component>
|
||||
<component name="RecentsManager">
|
||||
<key name="CopyFile.RECENT_KEYS">
|
||||
<recent name="C:\Users\402\Downloads\AbsenceManager\lib" />
|
||||
</key>
|
||||
<key name="MoveFile.RECENT_KEYS">
|
||||
<recent name="C:\Users\402\IdeaProjects\AbsenceManager\sql" />
|
||||
</key>
|
||||
</component>
|
||||
<component name="RunDashboard">
|
||||
<option name="ruleStates">
|
||||
<list>
|
||||
<RuleState>
|
||||
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
|
||||
</RuleState>
|
||||
<RuleState>
|
||||
<option name="name" value="StatusDashboardGroupingRule" />
|
||||
</RuleState>
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="RunManager" selected="JUnit.TestDatabaseUtil">
|
||||
<configuration name="AbsenceManager 中的 test.model " type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
||||
<module name="AbsenceManager" />
|
||||
<extension name="coverage">
|
||||
<pattern>
|
||||
<option name="PATTERN" value="test.model.*" />
|
||||
<option name="ENABLED" value="true" />
|
||||
</pattern>
|
||||
</extension>
|
||||
<option name="PACKAGE_NAME" value="test.model" />
|
||||
<option name="TEST_OBJECT" value="package" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration name="TestDatabaseUtil" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
||||
<module name="AbsenceManager" />
|
||||
<extension name="coverage">
|
||||
<pattern>
|
||||
<option name="PATTERN" value="test.util.*" />
|
||||
<option name="ENABLED" value="true" />
|
||||
</pattern>
|
||||
</extension>
|
||||
<option name="PACKAGE_NAME" value="test.util" />
|
||||
<option name="MAIN_CLASS_NAME" value="test.util.TestDatabaseUtil" />
|
||||
<option name="TEST_OBJECT" value="class" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="JUnit.TestDatabaseUtil" />
|
||||
<item itemvalue="JUnit.AbsenceManager 中的 test.model " />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
</component>
|
||||
<component name="SvnConfiguration">
|
||||
<configuration />
|
||||
</component>
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
<changelist id="a16f9e6c-d3d8-4ed4-a07c-f75cc82e9a65" name="默认更改列表" comment="" />
|
||||
<created>1734415810914</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1734415810914</updated>
|
||||
<workItem from="1734415814389" duration="1508000" />
|
||||
<workItem from="1734575321116" duration="4743000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="1" />
|
||||
</component>
|
||||
</project>
|
12
AbsenceManager.iml
Normal file
12
AbsenceManager.iml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="lib" level="project" />
|
||||
</component>
|
||||
</module>
|
BIN
lib/hamcrest-core-1.3.jar
Normal file
BIN
lib/hamcrest-core-1.3.jar
Normal file
Binary file not shown.
BIN
lib/junit-4.13.2.jar
Normal file
BIN
lib/junit-4.13.2.jar
Normal file
Binary file not shown.
BIN
lib/mysql-connector-java-8.0.11.jar
Normal file
BIN
lib/mysql-connector-java-8.0.11.jar
Normal file
Binary file not shown.
BIN
out/production/AbsenceManager/model/ApprovalStatus.class
Normal file
BIN
out/production/AbsenceManager/model/ApprovalStatus.class
Normal file
Binary file not shown.
BIN
out/production/AbsenceManager/model/LeaveRequest.class
Normal file
BIN
out/production/AbsenceManager/model/LeaveRequest.class
Normal file
Binary file not shown.
BIN
out/production/AbsenceManager/model/Student.class
Normal file
BIN
out/production/AbsenceManager/model/Student.class
Normal file
Binary file not shown.
BIN
out/production/AbsenceManager/model/Teacher.class
Normal file
BIN
out/production/AbsenceManager/model/Teacher.class
Normal file
Binary file not shown.
BIN
out/production/AbsenceManager/test/model/TeacherTest.class
Normal file
BIN
out/production/AbsenceManager/test/model/TeacherTest.class
Normal file
Binary file not shown.
BIN
out/production/AbsenceManager/test/util/TestDatabaseUtil.class
Normal file
BIN
out/production/AbsenceManager/test/util/TestDatabaseUtil.class
Normal file
Binary file not shown.
BIN
out/production/AbsenceManager/util/DatabaseUtil.class
Normal file
BIN
out/production/AbsenceManager/util/DatabaseUtil.class
Normal file
Binary file not shown.
68
sql/init.sql
Normal file
68
sql/init.sql
Normal file
@ -0,0 +1,68 @@
|
||||
-- 创建数据库
|
||||
CREATE DATABASE IF NOT EXISTS absence_manager DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
USE absence_manager;
|
||||
|
||||
-- 创建学生表
|
||||
CREATE TABLE IF NOT EXISTS students (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
student_id VARCHAR(20) UNIQUE NOT NULL, -- 学号
|
||||
name VARCHAR(50) NOT NULL, -- 姓名
|
||||
class_name VARCHAR(50) NOT NULL, -- 班级
|
||||
contact VARCHAR(20), -- 联系方式
|
||||
college VARCHAR(50) NOT NULL, -- 学院
|
||||
major VARCHAR(50) NOT NULL, -- 专业
|
||||
password VARCHAR(50) NOT NULL -- 密码
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='学生信息表';
|
||||
|
||||
-- 创建教师表
|
||||
CREATE TABLE IF NOT EXISTS teachers (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
teacher_id VARCHAR(20) UNIQUE NOT NULL, -- 工号
|
||||
name VARCHAR(50) NOT NULL, -- 姓名
|
||||
department VARCHAR(50) NOT NULL, -- 部门
|
||||
contact VARCHAR(20), -- 联系方式
|
||||
password VARCHAR(50) NOT NULL -- 密码
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='教师信息表';
|
||||
|
||||
-- 创建请假申请表
|
||||
CREATE TABLE IF NOT EXISTS leave_requests (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
student_id INT NOT NULL, -- 关联学生ID
|
||||
start_time DATETIME NOT NULL, -- 开始时间
|
||||
end_time DATETIME NOT NULL, -- 结束时间
|
||||
duration DECIMAL(5,2) NOT NULL, -- 时长
|
||||
location VARCHAR(100) NOT NULL, -- 外出地址
|
||||
reason_type VARCHAR(50) NOT NULL, -- 外出事由类型
|
||||
reason_detail TEXT, -- 详细事由
|
||||
is_leaving_city BOOLEAN DEFAULT FALSE, -- 是否离津
|
||||
status VARCHAR(20) NOT NULL DEFAULT 'PENDING', -- 审批状态
|
||||
approver_id INT, -- 审批人ID
|
||||
approval_comment TEXT, -- 审批意见
|
||||
request_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, -- 申请时间
|
||||
approval_time TIMESTAMP NULL, -- 审批时间
|
||||
FOREIGN KEY (student_id) REFERENCES students(id),
|
||||
FOREIGN KEY (approver_id) REFERENCES teachers(id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='请假申请表';
|
||||
|
||||
-- 插入示例数据
|
||||
INSERT INTO students (student_id, name, class_name, contact, college, major, password) VALUES
|
||||
('2023208145', '李同学', '云计算G23-1', '15842087237', '信息工程学院', '云计算技术应用', '123456'),
|
||||
('2023208146', '张同学', '云计算G23-1', '15842087238', '信息工程学院', '云计算技术应用', '123456');
|
||||
|
||||
INSERT INTO teachers (teacher_id, name, department, contact, password) VALUES
|
||||
('2023001', '王老师', '信息工程学院', '13912345678', '123456'),
|
||||
('2023002', '李老师', '信息工程学院', '13912345679', '123456');
|
||||
|
||||
-- 插入请假申请示例数据
|
||||
INSERT INTO leave_requests (student_id, start_time, end_time, duration, location, reason_type, reason_detail, is_leaving_city, status, approver_id, approval_comment, request_time) VALUES
|
||||
(1, '2024-01-15 08:00:00', '2024-01-15 17:00:00', 9.00, '天津市河西区图书馆', '学习', '去图书馆学习准备考试', false, 'APPROVED', 1, '同意', '2024-01-14 10:00:00'),
|
||||
(2, '2024-01-16 13:00:00', '2024-01-16 17:30:00', 4.50, '天津市南开医院', '就医', '牙科复诊', false, 'APPROVED', 1, '注意安全', '2024-01-15 09:30:00'),
|
||||
(1, '2024-01-17 09:00:00', '2024-01-17 12:00:00', 3.00, '天津市档案馆', '办事', '办理个人档案', false, 'PENDING', null, null, '2024-01-16 16:20:00'),
|
||||
(2, '2024-01-18 14:00:00', '2024-01-18 18:00:00', 4.00, '和平区文化中心', '活动', '参加志愿者活动', false, 'REJECTED', 2, '活动时间与课程冲突', '2024-01-17 11:15:00'),
|
||||
(1, '2024-01-19 10:00:00', '2024-01-19 16:00:00', 6.00, '天津站', '返乡', '购买返乡车票', true, 'APPROVED', 2, '请注意防疫', '2024-01-18 14:40:00'),
|
||||
(2, '2024-01-20 09:30:00', '2024-01-20 11:30:00', 2.00, '河西区人才市场', '求职', '参加招聘会', false, 'PENDING', null, null, '2024-01-19 17:00:00'),
|
||||
(1, '2024-01-21 13:00:00', '2024-01-21 17:00:00', 4.00, '天津市第一中心医院', '就医', '例行体检', false, 'APPROVED', 1, '准假', '2024-01-20 10:25:00'),
|
||||
(2, '2024-01-22 08:00:00', '2024-01-22 18:00:00', 10.00, '滨海新区图书馆', '实习', '企业实地考察', false, 'PENDING', null, null, '2024-01-21 15:30:00'),
|
||||
(1, '2024-01-23 14:00:00', '2024-01-23 16:00:00', 2.00, '南开区政务中心', '办事', '办理身份证', false, 'APPROVED', 2, '同意', '2024-01-22 09:45:00'),
|
||||
(2, '2024-01-24 09:00:00', '2024-01-24 18:00:00', 9.00, '天津市人民医院', '就医', '陪同父亲做检查', false, 'PENDING', null, null, '2024-01-23 16:50:00');
|
21
src/model/ApprovalStatus.java
Normal file
21
src/model/ApprovalStatus.java
Normal file
@ -0,0 +1,21 @@
|
||||
|
||||
package model;
|
||||
|
||||
/**
|
||||
* 请假审批状态枚举类
|
||||
*/
|
||||
public enum ApprovalStatus {
|
||||
PENDING("待审批"), // 等待审批
|
||||
APPROVED("已批准"), // 已经批准
|
||||
REJECTED("已驳回"); // 已经驳回
|
||||
|
||||
private final String description; // 状态描述
|
||||
|
||||
ApprovalStatus(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
}
|
155
src/model/LeaveRequest.java
Normal file
155
src/model/LeaveRequest.java
Normal file
@ -0,0 +1,155 @@
|
||||
|
||||
package model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class LeaveRequest {
|
||||
private int id; // 数据库主键ID
|
||||
private Student student; // 学生信息
|
||||
private Date startTime; // 开始时间
|
||||
private Date endTime; // 结束时间
|
||||
private double duration; // 时长
|
||||
private String location; // 外出地址
|
||||
private String reasonType; // 外出事由类型
|
||||
private String reasonDetail; // 详细事由
|
||||
private boolean isLeavingCity; // 是否离津
|
||||
private ApprovalStatus status; // 审批状态
|
||||
private Teacher approver; // 审批人
|
||||
private String approvalComment; // 审批意见
|
||||
private Date requestTime; // 申请时间
|
||||
private Date approvalTime; // 审批时间
|
||||
|
||||
// 构造方法
|
||||
|
||||
public LeaveRequest(int id, Student student, Date startTime, Date endTime, double duration, String location,
|
||||
String reasonType, String reasonDetail, boolean isLeavingCity, ApprovalStatus status,
|
||||
Teacher approver, String approvalComment, Date requestTime, Date approvalTime) {
|
||||
this.id = id;
|
||||
this.student = student;
|
||||
this.startTime = startTime;
|
||||
this.endTime = endTime;
|
||||
this.duration = duration;
|
||||
this.location = location;
|
||||
this.reasonType = reasonType;
|
||||
this.reasonDetail = reasonDetail;
|
||||
this.isLeavingCity = isLeavingCity;
|
||||
this.status = status;
|
||||
this.approver = approver;
|
||||
this.approvalComment = approvalComment;
|
||||
this.requestTime = requestTime;
|
||||
this.approvalTime = approvalTime;
|
||||
}
|
||||
// getter和setter方法
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Student getStudent() {
|
||||
return student;
|
||||
}
|
||||
|
||||
public void setStudent(Student student) {
|
||||
this.student = student;
|
||||
}
|
||||
|
||||
public Date getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setStartTime(Date startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
public Date getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public void setEndTime(Date endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
|
||||
public double getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
public void setDuration(double duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public String getReasonType() {
|
||||
return reasonType;
|
||||
}
|
||||
|
||||
public void setReasonType(String reasonType) {
|
||||
this.reasonType = reasonType;
|
||||
}
|
||||
|
||||
public String getReasonDetail() {
|
||||
return reasonDetail;
|
||||
}
|
||||
|
||||
public void setReasonDetail(String reasonDetail) {
|
||||
this.reasonDetail = reasonDetail;
|
||||
}
|
||||
|
||||
public boolean isLeavingCity() {
|
||||
return isLeavingCity;
|
||||
}
|
||||
|
||||
public void setLeavingCity(boolean leavingCity) {
|
||||
isLeavingCity = leavingCity;
|
||||
}
|
||||
|
||||
public ApprovalStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(ApprovalStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Teacher getApprover() {
|
||||
return approver;
|
||||
}
|
||||
|
||||
public void setApprover(Teacher approver) {
|
||||
this.approver = approver;
|
||||
}
|
||||
|
||||
public String getApprovalComment() {
|
||||
return approvalComment;
|
||||
}
|
||||
|
||||
public void setApprovalComment(String approvalComment) {
|
||||
this.approvalComment = approvalComment;
|
||||
}
|
||||
|
||||
public Date getRequestTime() {
|
||||
return requestTime;
|
||||
}
|
||||
|
||||
public void setRequestTime(Date requestTime) {
|
||||
this.requestTime = requestTime;
|
||||
}
|
||||
|
||||
public Date getApprovalTime() {
|
||||
return approvalTime;
|
||||
}
|
||||
|
||||
public void setApprovalTime(Date approvalTime) {
|
||||
this.approvalTime = approvalTime;
|
||||
}
|
||||
}
|
92
src/model/Student.java
Normal file
92
src/model/Student.java
Normal file
@ -0,0 +1,92 @@
|
||||
package model;
|
||||
|
||||
public class Student {
|
||||
private int id; // 数据库主键ID
|
||||
private String studentId; // 学号
|
||||
private String name; // 学生姓名
|
||||
private String className; // 班级
|
||||
private String contact; // 联系方式
|
||||
private String college; // 学院
|
||||
private String major; // 专业
|
||||
private String password; // 登录密码
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getStudentId() {
|
||||
return studentId;
|
||||
}
|
||||
|
||||
public void setStudentId(String studentId) {
|
||||
this.studentId = studentId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
public void setClassName(String className) {
|
||||
this.className = className;
|
||||
}
|
||||
|
||||
public String getContact() {
|
||||
return contact;
|
||||
}
|
||||
|
||||
public void setContact(String contact) {
|
||||
this.contact = contact;
|
||||
}
|
||||
|
||||
public String getCollege() {
|
||||
return college;
|
||||
}
|
||||
|
||||
public void setCollege(String college) {
|
||||
this.college = college;
|
||||
}
|
||||
|
||||
public String getMajor() {
|
||||
return major;
|
||||
}
|
||||
|
||||
public void setMajor(String major) {
|
||||
this.major = major;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public Student(int id, String studentId, String name, String className, String contact, String college, String major, String password) {
|
||||
this.id = id;
|
||||
this.studentId = studentId;
|
||||
this.name = name;
|
||||
this.className = className;
|
||||
this.contact = contact;
|
||||
this.college = college;
|
||||
this.major = major;
|
||||
this.password = password;
|
||||
}
|
||||
// 构造方法
|
||||
|
||||
|
||||
|
||||
// getter和setter方法
|
||||
}
|
79
src/model/Teacher.java
Normal file
79
src/model/Teacher.java
Normal file
@ -0,0 +1,79 @@
|
||||
package model;
|
||||
|
||||
/**
|
||||
* 教师实体类
|
||||
*/
|
||||
public class Teacher {
|
||||
private int id; // 数据库主键ID
|
||||
private String teacherId; // 教师工号
|
||||
private String name; // 教师姓名
|
||||
private String department; // 所属部门
|
||||
private String contact; // 联系方式
|
||||
private String password; // 登录密码
|
||||
|
||||
// 使用 IDE 自动生成以下内容:
|
||||
public Teacher( String teacherId, String name, String department, String contact,
|
||||
String password) {
|
||||
|
||||
this.teacherId = teacherId;
|
||||
this.name = name;
|
||||
this.department = department;
|
||||
this.contact = contact;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public Teacher() {
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTeacherId() {
|
||||
return teacherId;
|
||||
}
|
||||
|
||||
public void setTeacherId(String teacherId) {
|
||||
this.teacherId = teacherId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDepartment() {
|
||||
return department;
|
||||
}
|
||||
|
||||
public void setDepartment(String department) {
|
||||
this.department = department;
|
||||
}
|
||||
|
||||
public String getContact() {
|
||||
return contact;
|
||||
}
|
||||
|
||||
public void setContact(String contact) {
|
||||
this.contact = contact;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
|
||||
// 构造方法
|
||||
// getter 和 setter 方法
|
||||
}
|
50
src/test/model/TeacherTest.java
Normal file
50
src/test/model/TeacherTest.java
Normal file
@ -0,0 +1,50 @@
|
||||
package test.model;
|
||||
|
||||
import model.Teacher;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class TeacherTest {
|
||||
|
||||
@Test
|
||||
public void testConstructorAndGetters() {
|
||||
String teacherId = "T001";
|
||||
String name = "张老师";
|
||||
String department = "计算机系";
|
||||
String contact = "13800138000";
|
||||
String password = "password123";
|
||||
|
||||
Teacher teacher = new Teacher(teacherId, name, department, contact, password);
|
||||
|
||||
assertEquals("教师工号应匹配", teacherId, teacher.getTeacherId());
|
||||
assertEquals("教师姓名应匹配", name, teacher.getName());
|
||||
assertEquals("所属部门应匹配", department, teacher.getDepartment());
|
||||
assertEquals("联系方式应匹配", contact, teacher.getContact());
|
||||
assertEquals("密码应匹配", password, teacher.getPassword());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetters() {
|
||||
Teacher teacher = new Teacher();
|
||||
|
||||
String teacherId = "T002";
|
||||
String name = "李老师";
|
||||
String department = "数学系";
|
||||
String contact = "13900139000";
|
||||
String password = "newpass123";
|
||||
|
||||
|
||||
teacher.setTeacherId(teacherId);
|
||||
teacher.setName(name);
|
||||
teacher.setDepartment(department);
|
||||
teacher.setContact(contact);
|
||||
teacher.setPassword(password);
|
||||
|
||||
|
||||
assertEquals("教师工号应匹配", teacherId, teacher.getTeacherId());
|
||||
assertEquals("教师姓名应匹配", name, teacher.getName());
|
||||
assertEquals("所属部门应匹配", department, teacher.getDepartment());
|
||||
assertEquals("联系方式应匹配", contact, teacher.getContact());
|
||||
assertEquals("密码应匹配", password, teacher.getPassword());
|
||||
}
|
||||
}
|
19
src/test/util/TestDatabaseUtil.java
Normal file
19
src/test/util/TestDatabaseUtil.java
Normal file
@ -0,0 +1,19 @@
|
||||
package test.util;
|
||||
import org.junit.Test;
|
||||
import java.sql.Connection;
|
||||
import util.DatabaseUtil;
|
||||
import static org.junit.Assert.*;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class TestDatabaseUtil {
|
||||
@Test
|
||||
public void testGetConnection() {
|
||||
try (Connection connection = DatabaseUtil.getConnection()) {
|
||||
|
||||
assertNotNull("数据库连接不应该为空", connection);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
24
src/util/DatabaseUtil.java
Normal file
24
src/util/DatabaseUtil.java
Normal file
@ -0,0 +1,24 @@
|
||||
package util;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class DatabaseUtil {
|
||||
private static final String URL =
|
||||
"jdbc:mysql://localhost:8200/absence_manager?useSSL=false&serverTimezone=UTC" +
|
||||
"&characterEncoding=UTF-8";
|
||||
private static final String USERNAME = "root";
|
||||
private static final String PASSWORD = "admin";
|
||||
|
||||
static {
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static Connection getConnection() throws SQLException {
|
||||
return DriverManager.getConnection(URL, USERNAME, PASSWORD);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user