数据库设计部分代码:
-- 创建学生表
CREATE TABLE students (
student_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
date_of_birth DATE,
gender VARCHAR(10),
class_id INT,
FOREIGN KEY (class_id) REFERENCES classes(class_id)
);
-- 创建老师表
CREATE TABLE teachers (
teacher_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
date_of_birth DATE,
gender VARCHAR(10)
);
-- 创建班级表
CREATE TABLE classes (
class_id INT PRIMARY KEY,
class_name VARCHAR(50),
teacher_id INT,
FOREIGN KEY (teacher_id) REFERENCES teachers(teacher_id)
);
-- 创建课程表
CREATE TABLE courses (
course_id INT PRIMARY KEY,
course_name VARCHAR(50),
class_id INT,
teacher_id INT,
FOREIGN KEY (class_id) REFERENCES classes(class_id),
FOREIGN KEY (teacher_id) REFERENCES teachers(teacher_id)
);
-- 创建家长表
CREATE TABLE parents (
parent_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
contact_number VARCHAR(15)
);
-- 创建学生与家长的关系表(假设一个学生可以有多个家长,一个家长可以有多个孩子)
CREATE TABLE student_parent_relationship (
student_id INT,
parent_id INT,
PRIMARY KEY (student_id, parent_id),
FOREIGN KEY (student_id) REFERENCES students(student_id),
FOREIGN KEY (parent_id) REFERENCES parents(parent_id)
);
-- 创建考勤表
CREATE TABLE attendance (
attendance_id INT PRIMARY KEY,
student_id INT,
course_id INT,
attendance_date DATE,
status VARCHAR(10), -- 例如:出勤、迟到、旷课等
FOREIGN KEY (student_id) REFERENCES students(student_id),
FOREIGN KEY (course_id) REFERENCES courses(course_id)
);
前端页面实现部分代码:
<template>
<div>
<h2>学生管理</h2>
<!-- 显示学生列表 -->
<ul>
<li v-for="student in students" :key="student.id">
{{ student.firstName }} {{ student.lastName }}
<!-- 其他学生信息 -->
</li>
</ul>
</div>
</template>
<script>
export default {
data() {
return {
students: [] // 从后端获取的学生列表数据
};
},
mounted() {
// 从后端获取学生数据
// 示例:使用axios进行异步请求
axios.get('/api/students')
.then(response => {
this.students = response.data;
})
.catch(error => {
console.error('Error fetching students: ', error);
});
}
};
</script>
<template>
<div>
<h2>课程管理</h2>
<!-- 显示课程列表 -->
<ul>
<li v-for="course in courses" :key="course.id">
{{ course.courseName }}
<!-- 其他课程信息 -->
</li>
</ul>
</div>
</template>
<script>
export default {
data() {
return {
courses: [] // 从后端获取的课程列表数据
};
},
mounted() {
// 从后端获取课程数据
// 示例:使用axios进行异步请求
axios.get('/api/courses')
.then(response => {
this.courses = response.data;
})
.catch(error => {
console.error('Error fetching courses: ', error);
});
}
};
</script>
后端模块设计部分代码:
@Entity
public class Student {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String firstName;
private String lastName;
private LocalDate dateOfBirth;
private String gender;
// Getters and setters
}
@Repository
public interface StudentRepository extends JpaRepository<Student, Long> {
// 自定义查询方法
}
@RestController
@RequestMapping("/api/students")
public class StudentController {
@Autowired
private StudentRepository studentRepository;
@GetMapping
public List<Student> getAllStudents() {
return studentRepository.findAll();
}
@PostMapping
public Student addStudent(@RequestBody Student student) {
return studentRepository.save(student);
}
// 其他学生管理操作
}
@Entity
public class Course {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String courseName;
// Other course attributes
// Getters and setters
}
@Repository
public interface CourseRepository extends JpaRepository<Course, Long> {
// 自定义查询方法
}
@RestController
@RequestMapping("/api/courses")
public class CourseController {
@Autowired
private CourseRepository courseRepository;
@GetMapping
public List<Course> getAllCourses() {
return courseRepository.findAll();
}
@PostMapping
public Course addCourse(@RequestBody Course course) {
return courseRepository.save(course);
}
// 其他课程管理操作
}
系统实现部分页面展示: