This commit is contained in:
parent
feb3d8bace
commit
bd09ffba19
|
@ -26,4 +26,6 @@ public interface ScoreMapper {
|
|||
void insertScore(Score score);
|
||||
void updateScore(Score score);
|
||||
void deleteScoreById(Integer scoreId);
|
||||
// 根据课程ID获取所有相关的成绩ID
|
||||
List<Score> getScoresWithNamesByStudentId(String number);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,6 @@ import lombok.Data;
|
|||
|
||||
@Data
|
||||
public class Course extends BaseEntity{
|
||||
private Integer id;
|
||||
private String id;
|
||||
private String name;
|
||||
}
|
||||
|
|
|
@ -55,6 +55,23 @@
|
|||
JOIN course c ON s.course_id = c.id
|
||||
WHERE s.student_id = #{studentId}
|
||||
</select>
|
||||
<select id="getScoresWithNamesByStudentId" resultType="edu.hjf.pojo.Score">
|
||||
SELECT
|
||||
s.id AS score_id,
|
||||
s.student_id,
|
||||
s.course_id,
|
||||
s.score,
|
||||
st.name AS student_name,
|
||||
c.name AS course_name
|
||||
FROM
|
||||
score s
|
||||
JOIN
|
||||
student st ON s.student_id = st.id
|
||||
JOIN
|
||||
course c ON s.course_id = c.id
|
||||
WHERE
|
||||
s.student_id = #{number}
|
||||
</select>
|
||||
|
||||
<insert id="insertScore">
|
||||
INSERT INTO score (student_id, course_id, score, create_time) VALUES (#{studentId}, #{courseId}, #{score}, #{createTime})
|
||||
|
|
|
@ -16,7 +16,18 @@ import java.time.LocalDate;
|
|||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import edu.hjf.mapper.CourseMapper;
|
||||
import edu.hjf.pojo.Course;
|
||||
import edu.hjf.pojo.Score;
|
||||
import edu.hjf.mapper.CourseMapper;
|
||||
import edu.hjf.mapper.ScoreMapper;
|
||||
import edu.hjf.pojo.Course;
|
||||
import edu.hjf.pojo.Score;
|
||||
import edu.hjf.pojo.Student;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@SpringBootTest
|
||||
class ApplicationTests {
|
||||
|
@ -28,7 +39,10 @@ class ApplicationTests {
|
|||
private StudentScoreMapper studentScoreMapper;
|
||||
@Autowired
|
||||
private AccountMapper accountMapper;
|
||||
|
||||
@Autowired
|
||||
private CourseMapper courseMapper;
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetAll(){
|
||||
// 查询所有学生信息
|
||||
|
@ -146,30 +160,82 @@ class ApplicationTests {
|
|||
System.out.println("课程:" + score.getCourse().getName() + ",成绩:" + score.getScore());
|
||||
}
|
||||
}
|
||||
/*@Test
|
||||
public void testGradeUpdate(){
|
||||
|
||||
// 1. 查询所有课程名
|
||||
@Test
|
||||
public void testGetAllCourses() {
|
||||
List<Course> 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");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetScoresWithNamesByStudentId() {
|
||||
List<Score> 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("学生记录为空");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 7. 增加某个人某条成绩
|
||||
@Test
|
||||
public void testAddScoreForStudent() {
|
||||
Score score = new Score();
|
||||
score.setStudentID("1214 2");
|
||||
score.setCourseID("101");
|
||||
score.setGrade(90);
|
||||
score.setStudentId("12138");
|
||||
score.setCourseId("103");
|
||||
score.setScore(95);
|
||||
score.setCreateTime(LocalDateTime.now());
|
||||
score.setCreateBy(1);
|
||||
scoreMapper.insertScore(score);
|
||||
}
|
||||
|
||||
// 8. 更新某个人某条成绩
|
||||
@Test
|
||||
public void testUpdateScoreForStudent() {
|
||||
Score score = new Score();
|
||||
score.setId(1);
|
||||
score.setScore(98);
|
||||
score.setUpdateTime(LocalDateTime.now());
|
||||
gradeMapper.update(score);
|
||||
System.out.println(score);
|
||||
score.setUpdateBy(1);
|
||||
scoreMapper.updateScore(score);
|
||||
}
|
||||
|
||||
|
||||
// 9. 删除某个人某条成绩
|
||||
@Test
|
||||
public void testGradeDelete(){
|
||||
gradeMapper.deleteByNo(24);
|
||||
public void testDeleteScoreForStudent() {
|
||||
scoreMapper.deleteScoreById(1);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetByNo(){
|
||||
Score score = gradeMapper.getByNo(1);
|
||||
System.out.println(score);
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue