基于javaweb+mysql的springboot学生成绩管理系统(java+springboot+vue+elementui+redis+mysql)
该学生成绩管理系统的核心功能包括学生管理、课程管理、成绩管理和报表查看等。以下是部分核心代码示例:
实体类 Student.java
@Entity
public class Student {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String email;
// 省略其他属性、getter和setter方法
}
实体类 Course.java
@Entity
public class Course {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String teacher;
// 省略其他属性、getter和setter方法
}
实体类 Score.java
@Entity
public class Score {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private int score;
// 关联属性
private Long studentId;
private Long courseId;
// 省略其他属性、getter和setter方法
}
Repository接口 StudentRepository.java
public interface StudentRepository extends JpaRepository<Student, Long> {
// 自定义查询方法
List<Student> findByNameContaining(String name);
}
Service层 StudentService.java
@Service
public class StudentService {
@Autowired
private StudentRepository studentRepository;
public List<Student> findByName(String name) {
return studentRepository.findByNameContaining(name);
}
// 省略其他方法
}
Controller层 StudentController.java
@RestController
@RequestMapping("/api/students")
public class StudentController {
@Autowired
private StudentService studentService;
@GetMapping("/search")
public ResponseEntity<List<Student>> searchStudents(@RequestParam String name) {
List<Student> students = studentService.findByName(name);
if (students.isEmpty()) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
return new ResponseEntity<>(students, HttpStatus.OK);
}
// 省略其他方法
}
前端 Vue 组件 StudentSearch.vue
<template>
<div>
<input type="text" v-model="searchQuery" placeholder="Search..." />
<ul>
<li v-for="student in filteredStudents" :key="student.id">
{{ student.name }}
</li>
</ul>
</div>
</template>
<script>
export default {
data() {
return {
searchQuery: '',
students: []
};
},
computed: {
filteredStudents() {
return this.students.filter((stude
评论已关闭