From 14f265b75cb69c074a36db33ceadbc1236a95783 Mon Sep 17 00:00:00 2001 From: SCDR Date: Wed, 9 Jun 2021 21:13:19 +0800 Subject: [PATCH 1/7] =?UTF-8?q?add:=E5=AE=9E=E7=8E=B0addStudent(List=20students)=20add:=E5=AE=9E=E7=8E=B0updateStudent(Long=20ui?= =?UTF-8?q?d,=20String=20field,=20Object=20o)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../student/StudentManageApplication.java | 1 + .../service/impl/StudentServiceImpl.java | 26 ++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/edu/tyut/selaba2/student/StudentManageApplication.java b/src/edu/tyut/selaba2/student/StudentManageApplication.java index 308e116..062c135 100644 --- a/src/edu/tyut/selaba2/student/StudentManageApplication.java +++ b/src/edu/tyut/selaba2/student/StudentManageApplication.java @@ -7,5 +7,6 @@ package edu.tyut.selaba2.student; public class StudentManageApplication { public static void main(String[] args) { + } } diff --git a/src/edu/tyut/selaba2/student/service/impl/StudentServiceImpl.java b/src/edu/tyut/selaba2/student/service/impl/StudentServiceImpl.java index 3798400..2ef2182 100644 --- a/src/edu/tyut/selaba2/student/service/impl/StudentServiceImpl.java +++ b/src/edu/tyut/selaba2/student/service/impl/StudentServiceImpl.java @@ -4,11 +4,15 @@ import edu.tyut.selaba2.student.entity.Student; import edu.tyut.selaba2.student.repository.StudentRepository; import edu.tyut.selaba2.student.service.StudentService; +import java.lang.reflect.InvocationTargetException; + +import java.lang.reflect.Method; import java.util.List; +import java.util.Locale; public class StudentServiceImpl implements StudentService { private final StudentRepository studentRepository; - StudentServiceImpl(StudentRepository studentRepository){ + public StudentServiceImpl(StudentRepository studentRepository){ this.studentRepository=studentRepository; } @@ -34,12 +38,28 @@ public class StudentServiceImpl implements StudentService { @Override public Integer addStudent(List students) { - return null; + int count=0; + for(Student st:students){ + if(studentRepository.insert(st)){ + count++; + } + } + return count; } @Override public Boolean updateStudent(Long uid, String field, Object o) { - return null; + if(studentRepository.getStudentByUid(uid)==null) { + return false; + } + Student Student= studentRepository.getStudentByUid(uid); + try { + Method met=Student.getClass().getMethod("set"+field.substring(0,1).toUpperCase(Locale.ROOT)+field.substring(1)); + met.invoke(this,o); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + return false; + } + return studentRepository.update(Student); } @Override -- Gitee From ebca12212c7103c932218d1ee76edc16f941b897 Mon Sep 17 00:00:00 2001 From: SCDR Date: Wed, 9 Jun 2021 22:05:08 +0800 Subject: [PATCH 2/7] =?UTF-8?q?bug:=E4=BF=AE=E6=AD=A3=E5=8F=8D=E5=B0=84?= =?UTF-8?q?=E7=94=A8=E6=B3=95=20feat:=E6=A0=A1=E9=AA=8C=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/StudentServiceImpl.java | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/edu/tyut/selaba2/student/service/impl/StudentServiceImpl.java b/src/edu/tyut/selaba2/student/service/impl/StudentServiceImpl.java index 2ef2182..a2289b7 100644 --- a/src/edu/tyut/selaba2/student/service/impl/StudentServiceImpl.java +++ b/src/edu/tyut/selaba2/student/service/impl/StudentServiceImpl.java @@ -52,14 +52,33 @@ public class StudentServiceImpl implements StudentService { if(studentRepository.getStudentByUid(uid)==null) { return false; } - Student Student= studentRepository.getStudentByUid(uid); + Student student= studentRepository.getStudentByUid(uid); try { - Method met=Student.getClass().getMethod("set"+field.substring(0,1).toUpperCase(Locale.ROOT)+field.substring(1)); - met.invoke(this,o); + String methodName="set"+field.substring(0,1).toUpperCase(Locale.ROOT)+field.substring(1); + Class argType; + switch(field){ + case "name": + case "department": + argType=String.class; + break; + case "classNumber": + case "sex": + case "age": + argType=Integer.class; + break; + default: + return false; + + } + Method met=student.getClass().getMethod(methodName,argType); + if(!o.getClass().equals(argType)){ + return false; + } + met.invoke(student,o); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { return false; } - return studentRepository.update(Student); + return studentRepository.update(student); } @Override -- Gitee From 5f56903f706a77e753624ae165b42bd9a12de271 Mon Sep 17 00:00:00 2001 From: SCDR Date: Wed, 9 Jun 2021 22:13:22 +0800 Subject: [PATCH 3/7] =?UTF-8?q?add:=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../selaba2/student/service/impl/StudentServiceImpl.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/edu/tyut/selaba2/student/service/impl/StudentServiceImpl.java b/src/edu/tyut/selaba2/student/service/impl/StudentServiceImpl.java index a2289b7..d86b2ca 100644 --- a/src/edu/tyut/selaba2/student/service/impl/StudentServiceImpl.java +++ b/src/edu/tyut/selaba2/student/service/impl/StudentServiceImpl.java @@ -50,12 +50,13 @@ public class StudentServiceImpl implements StudentService { @Override public Boolean updateStudent(Long uid, String field, Object o) { if(studentRepository.getStudentByUid(uid)==null) { - return false; + return false;//避免空指针 } Student student= studentRepository.getStudentByUid(uid); try { String methodName="set"+field.substring(0,1).toUpperCase(Locale.ROOT)+field.substring(1); Class argType; + //校验属性 switch(field){ case "name": case "department": @@ -70,14 +71,18 @@ public class StudentServiceImpl implements StudentService { return false; } - Method met=student.getClass().getMethod(methodName,argType); + //校验参数 if(!o.getClass().equals(argType)){ return false; } + //获取对应方法 + Method met=student.getClass().getMethod(methodName,argType); + //调用方法 met.invoke(student,o); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { return false; } + //更新 return studentRepository.update(student); } -- Gitee From bcae200f37ba68543b3f013e36e668db5b672db2 Mon Sep 17 00:00:00 2001 From: SCDR Date: Wed, 9 Jun 2021 20:28:59 +0800 Subject: [PATCH 4/7] =?UTF-8?q?fix:=E6=B7=BB=E5=8A=A0service=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E6=A8=A1=E6=9D=BF=20findStudentByClassNumberAndDepart?= =?UTF-8?q?ment=20=E5=92=8C=20addStudent=20=E6=A8=A1=E5=9D=97=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E7=B1=BB.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/misc.xml | 2 +- .../service/impl/StudentServiceImpl.java | 32 ++++++++++++++----- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 1e23d89..2a824a2 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/src/edu/tyut/selaba2/student/service/impl/StudentServiceImpl.java b/src/edu/tyut/selaba2/student/service/impl/StudentServiceImpl.java index a62100a..8c6f9b2 100644 --- a/src/edu/tyut/selaba2/student/service/impl/StudentServiceImpl.java +++ b/src/edu/tyut/selaba2/student/service/impl/StudentServiceImpl.java @@ -7,15 +7,13 @@ import edu.tyut.selaba2.student.service.StudentService; import java.util.List; public class StudentServiceImpl implements StudentService { - StudentRepository studentRepository; + private final StudentRepository studentRepository; StudentServiceImpl(StudentRepository studentRepository){ this.studentRepository=studentRepository; } @Override - public Student getStudentById(Long uid) { - return null; - } + public Student getStudentById(Long uid) { return null; } @Override public List findStudentByName(String name) { @@ -23,13 +21,31 @@ public class StudentServiceImpl implements StudentService { } @Override - public List findStudentByClassNumberAndDepartment(Integer classNumber, String department) { - return null; + public List findStudentByClassNumberAndDepartment(Integer classNumber, String department) { //@liaoyu + + //设置学生信息 + Student student = new Student(); + student.setClassNumber(classNumber); + student.setDepartment(department); + + //通过studentRepository接口的findStudentByExample()查找. + List findSt = studentRepository.findStudentByExample(student); + + return findSt; } @Override - public Boolean addStudent(Student student) { - return null; + public Boolean addStudent(Student student) { // @liaoyu + + //如果学生的Uid存在,则返回false + if(student.getUid()!=null){ + return false; + } + + //插入学生信息.并返回true. + studentRepository.insert(student); + + return true; } @Override -- Gitee From 5e2d5623039f3233e935193dcbd209b5e46c57c5 Mon Sep 17 00:00:00 2001 From: SCDR Date: Wed, 16 Jun 2021 20:32:07 +0800 Subject: [PATCH 5/7] =?UTF-8?q?fix:=E4=BF=AE=E6=94=B9jdk=E4=B8=BA16?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/misc.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 2a824a2..8fd4bcb 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file -- Gitee From 4e5eda17a5e6ab4459c9c45cc04df7dba12c4e51 Mon Sep 17 00:00:00 2001 From: SCDR Date: Sat, 19 Jun 2021 18:39:20 +0800 Subject: [PATCH 6/7] =?UTF-8?q?feat:=E5=AE=9E=E7=8E=B0getStudentById=20fea?= =?UTF-8?q?t:=E5=AE=9E=E7=8E=B0findStudentByName=20feat:=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?updateStudent=20feat:=E5=AE=9E=E7=8E=B0deleteStudentById=20add:?= =?UTF-8?q?StudentService=E6=8E=A5=E5=8F=A3=E5=85=A8=E9=83=A8=E5=9C=A8Stud?= =?UTF-8?q?entServiceImpl=E5=AE=9E=E7=8E=B0=EF=BC=8C=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/misc.xml | 4 ++ StudentManagement.iml | 10 +++ .../service/impl/StudentServiceImpl.java | 61 ++++++++++++------- 3 files changed, 53 insertions(+), 22 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 8fd4bcb..aaba9f1 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,9 @@ + + diff --git a/StudentManagement.iml b/StudentManagement.iml index c90834f..c3dc060 100644 --- a/StudentManagement.iml +++ b/StudentManagement.iml @@ -7,5 +7,15 @@ + + + + + + + + + + \ No newline at end of file diff --git a/src/edu/tyut/selaba2/student/service/impl/StudentServiceImpl.java b/src/edu/tyut/selaba2/student/service/impl/StudentServiceImpl.java index 013d0da..96cecbc 100644 --- a/src/edu/tyut/selaba2/student/service/impl/StudentServiceImpl.java +++ b/src/edu/tyut/selaba2/student/service/impl/StudentServiceImpl.java @@ -5,23 +5,35 @@ import edu.tyut.selaba2.student.repository.StudentRepository; import edu.tyut.selaba2.student.service.StudentService; import java.lang.reflect.InvocationTargetException; - import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.List; import java.util.Locale; +/** + * 实现StudentService接口 + */ public class StudentServiceImpl implements StudentService { private final StudentRepository studentRepository; - public StudentServiceImpl(StudentRepository studentRepository){ - this.studentRepository=studentRepository; + + /** + * 注入依赖 + * @param studentRepository 实现了studentRepository接口的实例 + */ + public StudentServiceImpl(StudentRepository studentRepository) { + this.studentRepository = studentRepository; } @Override - public Student getStudentById(Long uid) { return null; } + public Student getStudentById(Long uid) { + return studentRepository.getStudentByUid(uid); + } @Override public List findStudentByName(String name) { - return null; + Student exampleStudent = new Student(); + exampleStudent.setName(name); + return studentRepository.findStudentByExample(exampleStudent); } @Override @@ -42,7 +54,7 @@ public class StudentServiceImpl implements StudentService { public Boolean addStudent(Student student) { // @liaoyu //如果学生的Uid存在,则返回false - if(student.getUid()!=null){ + if (student.getUid() != null) { return false; } @@ -54,9 +66,9 @@ public class StudentServiceImpl implements StudentService { @Override public Integer addStudent(List students) { - int count=0; - for(Student st:students){ - if(studentRepository.insert(st)){ + int count = 0; + for (Student st : students) { + if (studentRepository.insert(st)) { count++; } } @@ -65,50 +77,55 @@ public class StudentServiceImpl implements StudentService { @Override public Boolean updateStudent(Long uid, String field, Object o) { - if(studentRepository.getStudentByUid(uid)==null) { + if (studentRepository.getStudentByUid(uid) == null) { return false;//避免空指针 } - Student student= studentRepository.getStudentByUid(uid); + Student student = studentRepository.getStudentByUid(uid); try { - String methodName="set"+field.substring(0,1).toUpperCase(Locale.ROOT)+field.substring(1); + String methodName = "set" + field.substring(0, 1).toUpperCase(Locale.ROOT) + field.substring(1); Class argType; //校验属性 - switch(field){ + switch (field) { case "name": case "department": - argType=String.class; + argType = String.class; break; case "classNumber": case "sex": case "age": - argType=Integer.class; + argType = Integer.class; break; default: return false; - } //校验参数 - if(!o.getClass().equals(argType)){ + if (!o.getClass().equals(argType)) { return false; } //获取对应方法 - Method met=student.getClass().getMethod(methodName,argType); + Method met = student.getClass().getMethod(methodName, argType); //调用方法 - met.invoke(student,o); + met.invoke(student, o); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { return false; } //更新 - return studentRepository.update(student); + return studentRepository.update(student); } @Override public Boolean updateStudent(String field, Object o) { - return null; + ArrayList allStudent = (ArrayList) studentRepository.findAll(); + for (Student student : allStudent) { + if (!(updateStudent(student.getUid(), field, o))) { + return false; + } + } + return true; } @Override public Boolean deleteStudentById(Long uid) { - return null; + return studentRepository.delete(uid); } } -- Gitee From 8c8b21f7321349db5436c53bdaa0be62064337e6 Mon Sep 17 00:00:00 2001 From: SCDR Date: Sat, 19 Jun 2021 18:46:29 +0800 Subject: [PATCH 7/7] =?UTF-8?q?add=EF=BC=9A=E6=9B=B4=E6=96=B0=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tyut/selaba2/student/service/impl/StudentServiceImpl.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/edu/tyut/selaba2/student/service/impl/StudentServiceImpl.java b/src/edu/tyut/selaba2/student/service/impl/StudentServiceImpl.java index 96cecbc..0de6c8a 100644 --- a/src/edu/tyut/selaba2/student/service/impl/StudentServiceImpl.java +++ b/src/edu/tyut/selaba2/student/service/impl/StudentServiceImpl.java @@ -57,7 +57,6 @@ public class StudentServiceImpl implements StudentService { if (student.getUid() != null) { return false; } - //插入学生信息.并返回true. studentRepository.insert(student); -- Gitee