소스 검색

美术阅卷11月新增需求-修复BUG

wangliang 5 년 전
부모
커밋
eb87b57874
1개의 변경된 파일11개의 추가작업 그리고 2개의 파일을 삭제
  1. 11 2
      stmms-ms-admin/src/main/java/cn/com/qmth/stmms/ms/admin/api/StudentApi.java

+ 11 - 2
stmms-ms-admin/src/main/java/cn/com/qmth/stmms/ms/admin/api/StudentApi.java

@@ -8,6 +8,7 @@ import cn.com.qmth.stmms.ms.core.repository.StudentRepo;
 import cn.com.qmth.stmms.ms.core.specification.StudentSpecification;
 import cn.com.qmth.stmms.ms.core.vo.Subject;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.DataIntegrityViolationException;
 import org.springframework.data.domain.Page;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
@@ -93,8 +94,16 @@ public class StudentApi {
      * @return
      */
     @RequestMapping(method = RequestMethod.POST)
-    public Student create(@RequestBody Student domain) {
-        return studentRepo.save(domain);
+    public Student create(@RequestBody Student domain) throws Exception {
+        try {
+            return studentRepo.save(domain);
+        } catch (Exception e) {
+            if (e instanceof DataIntegrityViolationException) {
+                throw new Exception("修改失败,同一个考区不允许有重复的考号");
+            }
+            e.printStackTrace();
+        }
+        return null;
     }
 
     /**