From f499ab2a8a675bfa432b728d7e7368d8982e5371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B8=AD=E9=B8=AD=E9=B8=AD=E9=B8=AD?= <14864967+beamateur20@user.noreply.gitee.com> Date: Thu, 21 Nov 2024 15:03:18 +0800 Subject: [PATCH] 202101080119 --- SimpleStudentManagementSystem/.gitignore | 33 +++ SimpleStudentManagementSystem/pom.xml | 93 +++++++ .../src/main/java/edu/tq/Application.java | 15 ++ .../controller/AccountStudentController.java | 30 +++ .../edu/tq/controller/CourseController.java | 36 +++ .../edu/tq/controller/LoginController.java | 35 +++ .../edu/tq/controller/StudentController.java | 52 ++++ .../java/edu/tq/mapper/AccountMapper.java | 18 ++ .../main/java/edu/tq/mapper/CourseMapper.java | 13 + .../main/java/edu/tq/mapper/ScoreMapper.java | 30 +++ .../java/edu/tq/mapper/StudentMapper.java | 33 +++ .../edu/tq/mapper/StudentScoreMapper.java | 8 + .../src/main/java/edu/tq/pojo/Account.java | 13 + .../src/main/java/edu/tq/pojo/BaseEntity.java | 13 + .../src/main/java/edu/tq/pojo/Course.java | 9 + .../src/main/java/edu/tq/pojo/Gender.java | 9 + .../src/main/java/edu/tq/pojo/Score.java | 20 ++ .../src/main/java/edu/tq/pojo/Student.java | 20 ++ .../main/java/edu/tq/pojo/StudentScore.java | 11 + .../java/edu/tq/service/AccountService.java | 11 + .../edu/tq/service/AccountStudentService.java | 12 + .../java/edu/tq/service/CourseService.java | 14 ++ .../java/edu/tq/service/ScoreService.java | 12 + .../java/edu/tq/service/StudentService.java | 12 + .../tq/service/impl/AccountServiceImpl.java | 32 +++ .../impl/AccountStudentServiceImpl.java | 53 ++++ .../tq/service/impl/CourseServiceImpl.java | 41 +++ .../edu/tq/service/impl/ScoreServiceImpl.java | 39 +++ .../tq/service/impl/StudentServiceImpl.java | 45 ++++ .../edu/tq/typehandler/GenderTypeHandler.java | 31 +++ .../src/main/resources/application.properties | 28 +++ .../main/resources/mapper/AccountMapper.xml | 54 ++++ .../main/resources/mapper/CourseMapper.xml | 23 ++ .../src/main/resources/mapper/ScoreMapper.xml | 88 +++++++ .../main/resources/mapper/StudentMapper.xml | 129 ++++++++++ .../resources/mapper/StudentScoreMapper.xml | 24 ++ .../main/resources/templates/addcourse.html | 13 + .../main/resources/templates/addscore.html | 15 ++ .../main/resources/templates/addstudent.html | 16 ++ .../src/main/resources/templates/courses.html | 25 ++ .../src/main/resources/templates/index.html | 15 ++ .../src/main/resources/templates/login.html | 17 ++ .../src/main/resources/templates/scores.html | 28 +++ .../src/main/resources/templates/student.html | 31 +++ .../resources/templates/updatecourse.html | 14 ++ .../main/resources/templates/updatescore.html | 16 ++ .../resources/templates/updatestudent.html | 16 ++ .../test/java/edu/tq/ApplicationTests.java | 235 ++++++++++++++++++ .../web/WEB-INF/web.xml | 6 + 49 files changed, 1586 insertions(+) create mode 100644 SimpleStudentManagementSystem/.gitignore create mode 100644 SimpleStudentManagementSystem/pom.xml create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/Application.java create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/controller/AccountStudentController.java create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/controller/CourseController.java create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/controller/LoginController.java create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/controller/StudentController.java create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/mapper/AccountMapper.java create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/mapper/CourseMapper.java create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/mapper/ScoreMapper.java create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/mapper/StudentMapper.java create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/mapper/StudentScoreMapper.java create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/Account.java create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/BaseEntity.java create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/Course.java create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/Gender.java create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/Score.java create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/Student.java create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/StudentScore.java create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/service/AccountService.java create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/service/AccountStudentService.java create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/service/CourseService.java create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/service/ScoreService.java create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/service/StudentService.java create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/service/impl/AccountServiceImpl.java create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/service/impl/AccountStudentServiceImpl.java create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/service/impl/CourseServiceImpl.java create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/service/impl/ScoreServiceImpl.java create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/service/impl/StudentServiceImpl.java create mode 100644 SimpleStudentManagementSystem/src/main/java/edu/tq/typehandler/GenderTypeHandler.java create mode 100644 SimpleStudentManagementSystem/src/main/resources/application.properties create mode 100644 SimpleStudentManagementSystem/src/main/resources/mapper/AccountMapper.xml create mode 100644 SimpleStudentManagementSystem/src/main/resources/mapper/CourseMapper.xml create mode 100644 SimpleStudentManagementSystem/src/main/resources/mapper/ScoreMapper.xml create mode 100644 SimpleStudentManagementSystem/src/main/resources/mapper/StudentMapper.xml create mode 100644 SimpleStudentManagementSystem/src/main/resources/mapper/StudentScoreMapper.xml create mode 100644 SimpleStudentManagementSystem/src/main/resources/templates/addcourse.html create mode 100644 SimpleStudentManagementSystem/src/main/resources/templates/addscore.html create mode 100644 SimpleStudentManagementSystem/src/main/resources/templates/addstudent.html create mode 100644 SimpleStudentManagementSystem/src/main/resources/templates/courses.html create mode 100644 SimpleStudentManagementSystem/src/main/resources/templates/index.html create mode 100644 SimpleStudentManagementSystem/src/main/resources/templates/login.html create mode 100644 SimpleStudentManagementSystem/src/main/resources/templates/scores.html create mode 100644 SimpleStudentManagementSystem/src/main/resources/templates/student.html create mode 100644 SimpleStudentManagementSystem/src/main/resources/templates/updatecourse.html create mode 100644 SimpleStudentManagementSystem/src/main/resources/templates/updatescore.html create mode 100644 SimpleStudentManagementSystem/src/main/resources/templates/updatestudent.html create mode 100644 SimpleStudentManagementSystem/src/test/java/edu/tq/ApplicationTests.java create mode 100644 SimpleStudentManagementSystem/web/WEB-INF/web.xml diff --git a/SimpleStudentManagementSystem/.gitignore b/SimpleStudentManagementSystem/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/SimpleStudentManagementSystem/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/SimpleStudentManagementSystem/pom.xml b/SimpleStudentManagementSystem/pom.xml new file mode 100644 index 0000000..5aece11 --- /dev/null +++ b/SimpleStudentManagementSystem/pom.xml @@ -0,0 +1,93 @@ + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.3.4 + + + + edu.maxxie + SimpleStudentManagementSystem + 0.0.1-SNAPSHOT + SimpleStudentManagementSystem + SimpleStudentManagementSystem + + + + + + + + + + + + + + + 17 + + + + org.springframework.boot + spring-boot-starter-web + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 3.0.3 + + + com.mysql + mysql-connector-j + runtime + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.mybatis.spring.boot + mybatis-spring-boot-starter-test + 3.0.3 + test + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + + org.springframework.boot + spring-boot-devtools + true + + + + + + org.graalvm.buildtools + native-maven-plugin + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + \ No newline at end of file diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/Application.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/Application.java new file mode 100644 index 0000000..ec38a4a --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/Application.java @@ -0,0 +1,15 @@ +package edu.tq; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication() +@MapperScan("edu.tq.mapper") +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/controller/AccountStudentController.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/controller/AccountStudentController.java new file mode 100644 index 0000000..a830ab2 --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/controller/AccountStudentController.java @@ -0,0 +1,30 @@ +package edu.tq.controller; + +import edu.tq.pojo.Student; +import edu.tq.service.AccountStudentService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.*; + +@Controller +public class AccountStudentController { + private final AccountStudentService accountStudentService; + @Autowired + public AccountStudentController(AccountStudentService accountStudentService) { + this.accountStudentService = accountStudentService; + } + @PostMapping("/accountstudent") + public String addAccountStudent(Student student, + Model model){ + accountStudentService.addStudentAccount(student); + return "redirect:/students"; + } + + @GetMapping("/deleteaccountstudent/{account}") + public String deleteAccountStudent(@PathVariable String account, Model model){ + System.out.println(account); + accountStudentService.deleteStudentAccount(account); + return "redirect:/students"; + } +} diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/controller/CourseController.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/controller/CourseController.java new file mode 100644 index 0000000..7e527fe --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/controller/CourseController.java @@ -0,0 +1,36 @@ +package edu.tq.controller; + +import edu.tq.pojo.Course; +import edu.tq.service.CourseService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + + +@RestController +@RequestMapping("/courses") +public class CourseController { + @Autowired +private CourseService courseService; + + @GetMapping + public List getAllCourses() { + return courseService.getAllCourses(); + } + + @PostMapping + public void addCourse(@RequestBody Course course) { + courseService.addCourse(course); + } + + @PutMapping + public void updateCourse(@RequestBody Course course) { + courseService.updateCourse(course); + } + + @DeleteMapping("/{courseId}") + public void deleteCourse(@PathVariable String courseId) { + courseService.deleteCourse(courseId); + } +} \ No newline at end of file diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/controller/LoginController.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/controller/LoginController.java new file mode 100644 index 0000000..e2089ff --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/controller/LoginController.java @@ -0,0 +1,35 @@ +package edu.tq.controller; + +import edu.tq.pojo.Account; +import edu.tq.service.AccountService; +import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +@Controller +public class LoginController { + private final AccountService accountService; + @Autowired + public LoginController(AccountService accountService) { + this.accountService = accountService; + } + @GetMapping({"/", "/login"}) + public String loginPage(Model model){ + model.addAttribute("title","教务系统"); + return "login"; + } + @PostMapping("/login") + public String login(String username, String password, Model model){ + boolean result = accountService.validate(username, password); + if (result){ + return "index"; + } + return "login"; + } +} diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/controller/StudentController.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/controller/StudentController.java new file mode 100644 index 0000000..9a792bb --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/controller/StudentController.java @@ -0,0 +1,52 @@ +package edu.tq.controller; + +import edu.tq.pojo.Account; +import edu.tq.pojo.Student; +import edu.tq.service.AccountService; +import edu.tq.service.StudentService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.Banner; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@Controller +public class StudentController { + private final StudentService studentService; + @Autowired + public StudentController(StudentService studentService) { + this.studentService = studentService; + } + // 加载页面 + @GetMapping("/studentpage") + public String getStudentPage(){ + return "student"; + } + + @GetMapping("addstudentpage") + public String addStudentPage(){ + return "addstudent"; + } + // 处理数据 + @GetMapping("/students") + public String getAllStudents(Model model){ + List students = studentService.getAllStudents(); + model.addAttribute("students",students); + return "student"; + } + @GetMapping("updatestudentpage/{id}") + public String updateStudentPage(@PathVariable String id, + Model model){ + Student student = studentService.getStudentById(id); + System.out.println(student); + model.addAttribute("student",student); + return "updatestudent"; + } + @PostMapping("/updatestudent") + public String updateStudent(@ModelAttribute Student student) { + studentService.updateStudent(student); + return "redirect:/students"; + } +} diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/mapper/AccountMapper.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/mapper/AccountMapper.java new file mode 100644 index 0000000..6222616 --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/mapper/AccountMapper.java @@ -0,0 +1,18 @@ +package edu.tq.mapper; + +import edu.tq.pojo.Account; + +import java.util.List; + + +public interface AccountMapper { + // 查询账号 + Account getAccount(String account); + // 添加账号 + void insertAccount(Account account); + + // 根据账号获取学生信息 + List getAccountWithDetails(); + + void deleteByAccount(String account); +} diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/mapper/CourseMapper.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/mapper/CourseMapper.java new file mode 100644 index 0000000..b555764 --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/mapper/CourseMapper.java @@ -0,0 +1,13 @@ +package edu.tq.mapper; + +import java.util.List; +import edu.tq.pojo.Course; +import org.apache.ibatis.annotations.Mapper; +import java.util.List; +@Mapper +public interface CourseMapper { + List getAllCourses(); + void insertCourse(Course course); + void updateCourse(Course course); + void deleteCourseById(String courseId); +} diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/mapper/ScoreMapper.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/mapper/ScoreMapper.java new file mode 100644 index 0000000..3de59a1 --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/mapper/ScoreMapper.java @@ -0,0 +1,30 @@ +package edu.tq.mapper; + +import edu.tq.pojo.Score; + +import java.util.List; + + +public interface ScoreMapper { + + // 新增成绩 + void insert(Score score); + + // 更新成绩 + void update(Score score); + + // 根据id删除成绩 + void deleteById(Integer id); + + // 批量删除成绩 + void deleteByIds(List ids); + + // 根据no查询成绩 + List getAll(); + List getAllScoresByStudentId(String studentId); + void insertScore(Score score); + void updateScore(Score score); + void deleteScoreById(Integer scoreId); + // 根据课程ID获取所有相关的成绩ID + List getScoresWithNamesByStudentId(String number); +} diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/mapper/StudentMapper.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/mapper/StudentMapper.java new file mode 100644 index 0000000..c094f2d --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/mapper/StudentMapper.java @@ -0,0 +1,33 @@ + +package edu.tq.mapper; + +import edu.tq.pojo.Student; +import org.apache.ibatis.annotations.*; + +import java.util.List; + +// 在运行时会自动生成该接口的实现类对象 并将该对交给IOC容器管理 成为一个bean + +public interface StudentMapper { + // 查询全部学生信息 + List getAll(); + + // 根据id查询学生 + Student getById(String id); + + // 添加学生 + void insertStudent(Student student); + + // 动态条件查询 根据姓名字数和性别查询 + List getByCondition(Integer len, Integer gender); + + // 动态更新学生 + void update(Student student); + + List getAllWithGender(); + + Student getStudentScoresById(String id); + + void deleteById(String id); +} + diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/mapper/StudentScoreMapper.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/mapper/StudentScoreMapper.java new file mode 100644 index 0000000..c3c49af --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/mapper/StudentScoreMapper.java @@ -0,0 +1,8 @@ +package edu.tq.mapper; + +import edu.tq.pojo.StudentScore; + + +public interface StudentScoreMapper { + StudentScore getByNo(String id); +} diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/Account.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/Account.java new file mode 100644 index 0000000..24cb4cb --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/Account.java @@ -0,0 +1,13 @@ +package edu.tq.pojo; + +import lombok.Data; + +@Data +public class Account extends BaseEntity { + private Integer id; + private String account; + private String password; + private Integer role = 1; + // 一对一查询 + private Student studentDetails; +} diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/BaseEntity.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/BaseEntity.java new file mode 100644 index 0000000..7e3d585 --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/BaseEntity.java @@ -0,0 +1,13 @@ +package edu.tq.pojo; + +import lombok.Data; + +import java.time.LocalDateTime; + +@Data +public class BaseEntity { + private Integer createBy; + private LocalDateTime createTime; + private Integer updateBy; + private LocalDateTime updateTime; +} diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/Course.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/Course.java new file mode 100644 index 0000000..f62789e --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/Course.java @@ -0,0 +1,9 @@ +package edu.tq.pojo; + +import lombok.Data; + +@Data +public class Course extends BaseEntity{ + private Integer id; + private String name; +} diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/Gender.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/Gender.java new file mode 100644 index 0000000..7d7f8d5 --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/Gender.java @@ -0,0 +1,9 @@ +package edu.tq.pojo; + +import lombok.Data; + +@Data +public class Gender extends BaseEntity { + private Integer id; + private String name; +} diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/Score.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/Score.java new file mode 100644 index 0000000..9e03b47 --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/Score.java @@ -0,0 +1,20 @@ +package edu.tq.pojo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +@Data + +public class Score extends BaseEntity{ + private Integer id; + private String studentId; + private String courseId; + private Integer score; + private LocalDateTime createTime; + // 学生和课程是一的一方 + private Student student; + private Course course; +} diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/Student.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/Student.java new file mode 100644 index 0000000..d646a50 --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/Student.java @@ -0,0 +1,20 @@ +package edu.tq.pojo; + +import lombok.*; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; + +@Data +public class Student extends BaseEntity { + private Integer id; + private String name; + private Integer gender; + // @DateTimeFormat(pattern = "yyyy-MM-dd") + private LocalDate birthday; + // 性别是一的一方 + private Gender genderDetails; + private List scores; +} diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/StudentScore.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/StudentScore.java new file mode 100644 index 0000000..9acb7fa --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/pojo/StudentScore.java @@ -0,0 +1,11 @@ +package edu.tq.pojo; + +import lombok.Data; + +import java.util.List; + +@Data +public class StudentScore { + private Student student; + private List scores; +} diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/service/AccountService.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/service/AccountService.java new file mode 100644 index 0000000..5efcb21 --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/service/AccountService.java @@ -0,0 +1,11 @@ +package edu.tq.service; + +import edu.tq.pojo.Account; + +public interface AccountService { + // 验证数据集账号密码 + boolean validate(String username, String password); + + // 添加账号 + void insertAccount(Account account); +} diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/service/AccountStudentService.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/service/AccountStudentService.java new file mode 100644 index 0000000..7933800 --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/service/AccountStudentService.java @@ -0,0 +1,12 @@ +package edu.tq.service; + + +import edu.tq.pojo.Student; +import org.springframework.transaction.annotation.Transactional; + +public interface AccountStudentService { + @Transactional + void addStudentAccount(Student student); + @Transactional + void deleteStudentAccount(String account); +} diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/service/CourseService.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/service/CourseService.java new file mode 100644 index 0000000..d9d5cb9 --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/service/CourseService.java @@ -0,0 +1,14 @@ +package edu.tq.service; + +import edu.tq.pojo.Course; + +import java.util.List; + +public interface CourseService { + List getAllCourses(); + void addCourse(Course course); + void updateCourse(Course course); + void deleteCourseById(String courseId); + + void deleteCourse(String courseId); +} diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/service/ScoreService.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/service/ScoreService.java new file mode 100644 index 0000000..9d1ab8a --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/service/ScoreService.java @@ -0,0 +1,12 @@ +package edu.tq.service; + +import edu.tq.pojo.Score; + +import java.util.List; + +public interface ScoreService { + List getAllScoresByStudentId(String studentId); + void addScore(Score score); + void updateScore(Score score); + void deleteScoreById(Integer scoreId); +} diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/service/StudentService.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/service/StudentService.java new file mode 100644 index 0000000..17f65fe --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/service/StudentService.java @@ -0,0 +1,12 @@ +package edu.tq.service; + +import edu.tq.pojo.Student; + +import java.util.List; + +public interface StudentService { + List getAllStudents(); + void insertStudent(Student student); + Student getStudentById(String id); + void updateStudent(Student student); +} diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/service/impl/AccountServiceImpl.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/service/impl/AccountServiceImpl.java new file mode 100644 index 0000000..efb5a41 --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/service/impl/AccountServiceImpl.java @@ -0,0 +1,32 @@ +package edu.tq.service.impl; + +import edu.tq.mapper.AccountMapper; +import edu.tq.pojo.Account; +import edu.tq.service.AccountService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class AccountServiceImpl implements AccountService { + + private final AccountMapper accountMapper; + + @Autowired + public AccountServiceImpl(AccountMapper accountMapper) { + this.accountMapper = accountMapper; + } + + @Override + public boolean validate(String username, String password) { + Account dbAccount = accountMapper.getAccount(username); + if(dbAccount != null && dbAccount.getPassword().equals(password)){ + return true; + } + return false; + } + + @Override + public void insertAccount(Account account) { + accountMapper.insertAccount(account); + } +} diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/service/impl/AccountStudentServiceImpl.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/service/impl/AccountStudentServiceImpl.java new file mode 100644 index 0000000..4831105 --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/service/impl/AccountStudentServiceImpl.java @@ -0,0 +1,53 @@ +package edu.tq.service.impl; + +import edu.tq.mapper.AccountMapper; +import edu.tq.mapper.StudentMapper; +import edu.tq.pojo.Account; +import edu.tq.pojo.Student; +import edu.tq.service.AccountService; +import edu.tq.service.AccountStudentService; +import edu.tq.service.StudentService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDateTime; + +@Service +public class AccountStudentServiceImpl implements AccountStudentService { + + private final AccountMapper accountMapper; + private final StudentMapper studentMapper; + @Autowired + public AccountStudentServiceImpl(AccountMapper accountMapper, StudentMapper studentMapper) { + this.accountMapper = accountMapper; + this.studentMapper = studentMapper; + } + @Override + @Transactional + public void addStudentAccount(Student student) { + LocalDateTime now = LocalDateTime.now(); + // 在数据库中创建Account + Account account = new Account(); + account.setAccount(String.valueOf(student.getId())); +// 学号 + account.setPassword("12346"); // 默认密码 + account.setRole(1); // 默认角色 + account.setCreateBy(1); + account.setCreateTime(now); + accountMapper.insertAccount(account); + // 在数据库中创建Student + student.setCreateBy(1); + student.setCreateTime(now); + studentMapper.insertStudent(student); + } + + @Override + @Transactional + public void deleteStudentAccount(String account) { + // 在数据库中删除student + studentMapper.deleteById(account); + // 在数据库中删除account + accountMapper.deleteByAccount(account); + } +} diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/service/impl/CourseServiceImpl.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/service/impl/CourseServiceImpl.java new file mode 100644 index 0000000..0c9d3d3 --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/service/impl/CourseServiceImpl.java @@ -0,0 +1,41 @@ +package edu.tq.service.impl; + + +import edu.tq.mapper.CourseMapper; +import edu.tq.pojo.Course; +import edu.tq.service.CourseService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class CourseServiceImpl implements CourseService { + @Autowired + private CourseMapper courseMapper; + + @Override + public List getAllCourses() { + return courseMapper.getAllCourses(); + } + + @Override + public void addCourse(Course course) { + courseMapper.insertCourse(course); + } + + @Override + public void updateCourse(Course course) { + courseMapper.updateCourse(course); + } + + @Override + public void deleteCourseById(String courseId) { + courseMapper.deleteCourseById(courseId); + } + + @Override + public void deleteCourse(String courseId) { + + } +} diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/service/impl/ScoreServiceImpl.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/service/impl/ScoreServiceImpl.java new file mode 100644 index 0000000..8f3d0e0 --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/service/impl/ScoreServiceImpl.java @@ -0,0 +1,39 @@ +package edu.tq.service.impl; + +import edu.tq.mapper.ScoreMapper; +import edu.tq.pojo.Score; +import edu.tq.service.ScoreService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.time.LocalDateTime; +import java.util.List; + +@Service +public class ScoreServiceImpl implements ScoreService { + + @Autowired + private ScoreMapper scoreMapper; + + @Override + public List getAllScoresByStudentId(String studentId) { + return scoreMapper.getAllScoresByStudentId(studentId); + } + + @Override + public void addScore(Score score) { + score.setCreateTime(LocalDateTime.now()); + scoreMapper.insertScore(score); + } + + @Override + public void updateScore(Score score) { + scoreMapper.updateScore(score); + } + + @Override + public void deleteScoreById(Integer scoreId) { + scoreMapper.deleteScoreById(scoreId); + } + +} diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/service/impl/StudentServiceImpl.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/service/impl/StudentServiceImpl.java new file mode 100644 index 0000000..797716d --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/service/impl/StudentServiceImpl.java @@ -0,0 +1,45 @@ +package edu.tq.service.impl; + +import edu.tq.mapper.AccountMapper; +import edu.tq.mapper.StudentMapper; +import edu.tq.pojo.Account; +import edu.tq.pojo.Student; +import edu.tq.service.StudentService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.time.LocalDateTime; +import java.util.List; +@Service +public class StudentServiceImpl implements StudentService { + private final StudentMapper studentMapper; + @Autowired + public StudentServiceImpl(StudentMapper studentMapper) { + this.studentMapper = studentMapper; + } + + @Override + public List getAllStudents() { + return studentMapper.getAll(); + } + @Override + public void insertStudent(Student student) { + // 添加学生之前,需要先创建账号 + studentMapper.insertStudent(student); + } + + + @Override + public Student getStudentById(String id) { + Student student = studentMapper.getById(id); + return student; + } + + @Override + public void updateStudent(Student student) { + student.setUpdateBy(1); + student.setUpdateTime(LocalDateTime.now()); + studentMapper.update(student); + } + +} diff --git a/SimpleStudentManagementSystem/src/main/java/edu/tq/typehandler/GenderTypeHandler.java b/SimpleStudentManagementSystem/src/main/java/edu/tq/typehandler/GenderTypeHandler.java new file mode 100644 index 0000000..7b9867e --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/java/edu/tq/typehandler/GenderTypeHandler.java @@ -0,0 +1,31 @@ +package edu.tq.typehandler; +import org.apache.ibatis.type.BaseTypeHandler; +import org.apache.ibatis.type.JdbcType; +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +public class GenderTypeHandler extends BaseTypeHandler { + @Override + public void setNonNullParameter(PreparedStatement ps, int i, Integer parameter, JdbcType jdbcType) throws SQLException { + ps.setInt(i, parameter); + } + + @Override + public Integer getNullableResult(ResultSet rs, String columnName) throws SQLException { + int genderCode = rs.getInt(columnName); + return genderCode; + } + + @Override + public Integer getNullableResult(ResultSet rs, int columnIndex) throws SQLException { + int genderCode = rs.getInt(columnIndex); + return genderCode; + } + + @Override + public Integer getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { + int genderCode = cs.getInt(columnIndex); + return genderCode; + } +} diff --git a/SimpleStudentManagementSystem/src/main/resources/application.properties b/SimpleStudentManagementSystem/src/main/resources/application.properties new file mode 100644 index 0000000..2df430f --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/resources/application.properties @@ -0,0 +1,28 @@ +spring.application.name=SimpleStudentManagementSystem +spring.devtools.restart.enabled=true +spring.devtools.restart.additional-paths=src/main/java +spring.jackson.time-zone=Asia/Shanghai +spring.devtools.restart.exclude=static/** + +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver +spring.datasource.url=jdbc:mysql://106.53.194.250:63306/mb202101080119 +spring.datasource.username=mb202101080119 +spring.datasource.password=UMFQEC304899 +#spring.datasource.url=jdbc:mysql://localhost:3306/mybatis +#spring.datasource.username=root +#spring.datasource.password=123456 +mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl +mybatis.configuration.map-underscore-to-camel-case=true + +mybatis.mapper-locations=classpath*:mapper/*.xml +mybatis.type-aliases-package=edu.tq.pojo + +spring.transaction.annotation-proxy-target-class=true + + +server.port=8080 +server.servlet.context-path=/ +spring.thymeleaf.cache=false +spring.thymeleaf.prefix=classpath:/templates/ +spring.thymeleaf.suffix=.html +spring.mvc.hiddenmethod.filter.enabled=true \ No newline at end of file diff --git a/SimpleStudentManagementSystem/src/main/resources/mapper/AccountMapper.xml b/SimpleStudentManagementSystem/src/main/resources/mapper/AccountMapper.xml new file mode 100644 index 0000000..e38c93f --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/resources/mapper/AccountMapper.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + insert into account(id, account, password, role, create_by) + values(#{id}, #{account}, #{password}, #{role}, #{createBy}) + + + + + + + + + DELETE FROM account WHERE account = #{account} + + + + + + + + + + + + + diff --git a/SimpleStudentManagementSystem/src/main/resources/mapper/CourseMapper.xml b/SimpleStudentManagementSystem/src/main/resources/mapper/CourseMapper.xml new file mode 100644 index 0000000..a388804 --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/resources/mapper/CourseMapper.xml @@ -0,0 +1,23 @@ + + + + + + + + INSERT INTO course (id, name) VALUES (#{id}, #{name}) + + + + UPDATE course SET name = #{name} WHERE id = #{id} + + + + DELETE FROM course WHERE id = #{courseId} + + + diff --git a/SimpleStudentManagementSystem/src/main/resources/mapper/ScoreMapper.xml b/SimpleStudentManagementSystem/src/main/resources/mapper/ScoreMapper.xml new file mode 100644 index 0000000..76d8452 --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/resources/mapper/ScoreMapper.xml @@ -0,0 +1,88 @@ + + + + + + insert into score(id, student_id, course_id, score, create_by, create_time) + values(#{id}, #{studentId}, #{courseId}, #{score}, #{createBy}, #{createTime}) + + + + + update grade + + grade = #{grade}, + update_time = #{updateTime} + + where no = #{no} + + + + + delete from score where id = #{id} + + + + delete from score where id in + + #{id} + + + + + + + + + + + + + + + + + + + + + INSERT INTO score (student_id, course_id, score, create_time) VALUES (#{studentId}, #{courseId}, #{score}, #{createTime}) + + + + UPDATE score SET score = #{score} WHERE id = #{id} + + + + DELETE FROM score WHERE id = #{scoreId} + + + \ No newline at end of file diff --git a/SimpleStudentManagementSystem/src/main/resources/mapper/StudentMapper.xml b/SimpleStudentManagementSystem/src/main/resources/mapper/StudentMapper.xml new file mode 100644 index 0000000..5916153 --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/resources/mapper/StudentMapper.xml @@ -0,0 +1,129 @@ + + + + + + select id, name, gender, birthday + from student + + + + + + + + + + + + + + + + + + INSERT INTO student (id, name, gender, birthday, create_by, create_time) + VALUES (#{id}, #{name}, #{gender}, #{birthday}, #{createBy}, #{createTime}) + + + + + + + update student + + name = #{name}, + gender = #{gender}, + birthday = #{birthday}, + update_by = #{updateBy}, + update_time = #{updateTime} + + where id = #{id} + + + + + + + + + + delete from student where id in + + #{id} + + + + + delete from student where id = #{id} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SimpleStudentManagementSystem/src/main/resources/mapper/StudentScoreMapper.xml b/SimpleStudentManagementSystem/src/main/resources/mapper/StudentScoreMapper.xml new file mode 100644 index 0000000..a25a407 --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/resources/mapper/StudentScoreMapper.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SimpleStudentManagementSystem/src/main/resources/templates/addcourse.html b/SimpleStudentManagementSystem/src/main/resources/templates/addcourse.html new file mode 100644 index 0000000..0586698 --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/resources/templates/addcourse.html @@ -0,0 +1,13 @@ + + + + 增加课程 + + +

增加课程

+
+

课程名:

+ +
+ + diff --git a/SimpleStudentManagementSystem/src/main/resources/templates/addscore.html b/SimpleStudentManagementSystem/src/main/resources/templates/addscore.html new file mode 100644 index 0000000..d464b81 --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/resources/templates/addscore.html @@ -0,0 +1,15 @@ + + + + 增加成绩 + + +

增加成绩

+
+

学生编号:

+

课程编号:

+

成绩:

+ +
+ + \ No newline at end of file diff --git a/SimpleStudentManagementSystem/src/main/resources/templates/addstudent.html b/SimpleStudentManagementSystem/src/main/resources/templates/addstudent.html new file mode 100644 index 0000000..8248c34 --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/resources/templates/addstudent.html @@ -0,0 +1,16 @@ + + + +

教务系统

+

学生管理——添加

+ 查询 + 添加 +
+

学号:

+

姓名:

+

性别:

+

出生日期:

+ +
+ + \ No newline at end of file diff --git a/SimpleStudentManagementSystem/src/main/resources/templates/courses.html b/SimpleStudentManagementSystem/src/main/resources/templates/courses.html new file mode 100644 index 0000000..682753b --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/resources/templates/courses.html @@ -0,0 +1,25 @@ + + + + 课程管理 + + +

课程列表

+增加课程 + + + + + + + + + + + +
课程编号课程名操作
+ 更新 + 删除 +
+ + diff --git a/SimpleStudentManagementSystem/src/main/resources/templates/index.html b/SimpleStudentManagementSystem/src/main/resources/templates/index.html new file mode 100644 index 0000000..7e8b7a7 --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/resources/templates/index.html @@ -0,0 +1,15 @@ + + + + + 教务系统 + + +

教务系统

+ + + \ No newline at end of file diff --git a/SimpleStudentManagementSystem/src/main/resources/templates/login.html b/SimpleStudentManagementSystem/src/main/resources/templates/login.html new file mode 100644 index 0000000..597be6d --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/resources/templates/login.html @@ -0,0 +1,17 @@ + + + + + Title + + +

+

登陆

+ +
+
+
+
+
+ + \ No newline at end of file diff --git a/SimpleStudentManagementSystem/src/main/resources/templates/scores.html b/SimpleStudentManagementSystem/src/main/resources/templates/scores.html new file mode 100644 index 0000000..39e98ee --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/resources/templates/scores.html @@ -0,0 +1,28 @@ + + + + 成绩管理 + + +

学生成绩列表

+增加成绩 + + + + + + + + + + + + + + +
学生姓名课程名成绩操作
+ 更新 + 删除 +
+ + \ No newline at end of file diff --git a/SimpleStudentManagementSystem/src/main/resources/templates/student.html b/SimpleStudentManagementSystem/src/main/resources/templates/student.html new file mode 100644 index 0000000..e9dee0c --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/resources/templates/student.html @@ -0,0 +1,31 @@ + + + +

教务系统

+

学生管理

+ 查询 + 添加 + + + + + + + + + + + + + + + + + +
id姓名性别出生日期删除操作更新操作
+ 删除 + + 更新 +
+ + \ No newline at end of file diff --git a/SimpleStudentManagementSystem/src/main/resources/templates/updatecourse.html b/SimpleStudentManagementSystem/src/main/resources/templates/updatecourse.html new file mode 100644 index 0000000..48e4e5f --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/resources/templates/updatecourse.html @@ -0,0 +1,14 @@ + + + + 更新课程 + + +

更新课程

+
+ +

课程名:

+ +
+ + diff --git a/SimpleStudentManagementSystem/src/main/resources/templates/updatescore.html b/SimpleStudentManagementSystem/src/main/resources/templates/updatescore.html new file mode 100644 index 0000000..fcec2eb --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/resources/templates/updatescore.html @@ -0,0 +1,16 @@ + + + + 更新成绩 + + +

更新成绩

+
+ +

学生姓名:

+

课程名:

+

成绩:

+ +
+ + diff --git a/SimpleStudentManagementSystem/src/main/resources/templates/updatestudent.html b/SimpleStudentManagementSystem/src/main/resources/templates/updatestudent.html new file mode 100644 index 0000000..75b3c6c --- /dev/null +++ b/SimpleStudentManagementSystem/src/main/resources/templates/updatestudent.html @@ -0,0 +1,16 @@ + + + +

教务系统

+

学生管理——更新

+ 查询 + 添加 +
+

学号:

+

姓名:

+

性别:

+

出生日期:

+ +
+ + \ No newline at end of file diff --git a/SimpleStudentManagementSystem/src/test/java/edu/tq/ApplicationTests.java b/SimpleStudentManagementSystem/src/test/java/edu/tq/ApplicationTests.java new file mode 100644 index 0000000..c9d6a14 --- /dev/null +++ b/SimpleStudentManagementSystem/src/test/java/edu/tq/ApplicationTests.java @@ -0,0 +1,235 @@ +package edu.tq; + +import edu.tq.mapper.*; +import edu.tq.pojo.*; +import edu.tq.service.AccountService; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.Arrays; +import java.util.List; + +@SpringBootTest +class ApplicationTests { + @Autowired + private StudentMapper studentMapper; + @Autowired + private ScoreMapper scoreMapper; + @Autowired + private StudentScoreMapper studentScoreMapper; + @Autowired + private AccountMapper accountMapper; + @Autowired + private AccountService accountService; + + @Autowired + private CourseMapper courseMapper;// 正确注入 AccountService + + @Test + public void testGetAll(){ + // 查询所有学生信息 + List stuList = studentMapper.getAll(); + System.out.println(stuList); + } + + @Test + public void testGetById(){ + // 根据 id 查学生 + Student stu = studentMapper.getById("12138"); + System.out.println(stu); + } + + @Test + public void testGetByCondition(){ + // 学生条件查询 + List stuList = studentMapper.getByCondition(null, null); + System.out.println(stuList); + } + + @Test + public void testInsertAccount(){ + // 新增账号 + Account account = new Account(); + account.setAccount("1214169"); + account.setPassword("123456"); + account.setCreateBy(1); + LocalDateTime now = LocalDateTime.now(); + account.setCreateTime(now); + + accountService.insertAccount(account); // 使用注入的 accountService 调用方法 + } + @Test + + public void testInsertStudent(){ + Student student = new Student(); + student.setId(12111); + student.setName("楼下小黑"); + student.setGender(1); + student.setBirthday(LocalDate.of(2002,10,14)); + student.setCreateBy(1); + LocalDateTime now = LocalDateTime.now(); + student.setCreateTime(now); +// studentMapper.insertStudent(student); + } + + + + @Test + public void testInsertScore(){ + Score score = new Score(); + score.setStudentId("12142"); + score.setCourseId("102"); + score.setScore(90); + score.setCreateBy(1); + LocalDateTime now = LocalDateTime.now(); + score.setCreateTime(now); + scoreMapper.insert(score); + System.out.println(score.getId()); + } + + @Test + public void testUpdateStudent(){ + Student student = new Student(); + student.setId(12141); + student.setName("张益达"); + student.setUpdateBy(1); + LocalDateTime now = LocalDateTime.now(); + student.setUpdateTime(now); + studentMapper.update(student); + } + + @Test + public void testDeleteScoreById(){ + // 删除一条成绩 + scoreMapper.deleteById(28); + } + + @Test + public void testDeleteByIds(){ + // 删除多条成绩 + List ids = Arrays.asList(29,30,31); + scoreMapper.deleteByIds(ids); + } + + @Test + public void testAccountWithDetails(){ + // 一对一 + List accounts = accountMapper.getAccountWithDetails(); + System.out.println(accounts); + } + + @Test + public void testStudentWithGender(){ + List students = studentMapper.getAllWithGender(); + System.out.println(students); + } + + @Test + public void testScoreWithName(){ + List scores = scoreMapper.getAll(); + System.out.println(scores); + } + @Test + public void testStudentGrade(){ + Student student = studentMapper.getStudentScoresById("12138"); + System.out.println("学生:" + student.getName()); + for (Score score : student.getScores()){ + System.out.println("课程:" + score.getCourse().getName() + ",成绩:" + score.getScore()); + System.out.println(score); + } + } + + @Test + public void testStudentGrade2(){ + StudentScore studentScore = studentScoreMapper.getByNo("12138"); + System.out.println("学生:" + studentScore.getStudent().getName()); + for (Score score : studentScore.getScores()){ + System.out.println("课程:" + score.getCourse().getName() + ",成绩:" + score.getScore()); + } + } + + + + + // 1. 查询所有课程名 + @Test + public void testGetAllCourses() { + List courses = courseMapper.getAllCourses(); + courses.forEach(course -> System.out.println(course.getName())); + } + + // 2. 增加某个课程 + @Test + public void testInsertCourse() { + Course course = new Course(); + course.setId(107); + course.setName("医学信息工程"); + course.setCreateBy(1); + course.setCreateTime(LocalDateTime.now()); + courseMapper.insertCourse(course); + } + + // 3. 更新某个课程 + @Test + public void testUpdateCourse() { + Course course = new Course(); + course.setId(103); + course.setName("线性代数"); + course.setUpdateBy(1); + course.setUpdateTime(LocalDateTime.now()); + courseMapper.updateCourse(course); + } + + // 4. 删除某个课程 + @Test + public void testDeleteCourse() { + courseMapper.deleteCourseById("107"); + } +//5.查询某个人所有成绩 + @Test + public void testGetScoresWithNamesByStudentId() { + List scores = scoreMapper.getScoresWithNamesByStudentId("12138"); + for (Score score : scores) { + if (score.getStudent() != null) { + System.out.println("学生姓名:" + score.getStudent().getName() + ",课程名:" + score.getCourse().getName() + ",成绩:" + score.getScore()); + } else { + System.out.println("学生记录为空"); + } + } + } + + + // 6. 增加某个人某条成绩 + @Test + public void testAddScoreForStudent() { + Score score = new Score(); + score.setStudentId("12138"); + score.setCourseId("103"); + score.setScore(95); + score.setCreateTime(LocalDateTime.now()); + score.setCreateBy(1); + scoreMapper.insertScore(score); + } + + // 7. 更新某个人某条成绩 + @Test + public void testUpdateScoreForStudent() { + Score score = new Score(); + score.setId(1); + score.setScore(98); + score.setUpdateTime(LocalDateTime.now()); + score.setUpdateBy(1); + scoreMapper.updateScore(score); + } + + // 8. 删除某个人某条成绩 + @Test + public void testDeleteScoreForStudent() { + scoreMapper.deleteScoreById(1); + } + +} + diff --git a/SimpleStudentManagementSystem/web/WEB-INF/web.xml b/SimpleStudentManagementSystem/web/WEB-INF/web.xml new file mode 100644 index 0000000..d80081d --- /dev/null +++ b/SimpleStudentManagementSystem/web/WEB-INF/web.xml @@ -0,0 +1,6 @@ + + + \ No newline at end of file