diff --git a/src/main/java/com/msdw/tms/controller/StudentController.java b/src/main/java/com/msdw/tms/controller/StudentController.java index 148f6c7..614c4b9 100644 --- a/src/main/java/com/msdw/tms/controller/StudentController.java +++ b/src/main/java/com/msdw/tms/controller/StudentController.java @@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; import java.io.IOException; import java.util.HashMap; import java.util.List; @@ -46,7 +47,7 @@ public class StudentController implements StudentControllerApi{ @Transactional @Override @PostMapping("/addStudent") - public R addStudent(@RequestBody StudentVo studentVo){ + public R addStudent(@RequestBody @Valid StudentVo studentVo){ studentVo.setSchoolId(ConstantUtils.Keda_schoolId); String account = studentVo.getAccount(); String phone = studentVo.getPhone(); @@ -130,7 +131,7 @@ public class StudentController implements StudentControllerApi{ @Override @Transactional @PutMapping("/updateStudent") - public R updateStudent(@RequestBody StudentVo studentVo) { + public R updateStudent(@RequestBody @Valid StudentVo studentVo) { studentVo.setSchoolId(ConstantUtils.Keda_schoolId);//设定学校id Integer studentId = studentVo.getStudentId(); diff --git a/src/main/java/com/msdw/tms/entity/vo/StudentVo.java b/src/main/java/com/msdw/tms/entity/vo/StudentVo.java index 4c477a3..648238d 100644 --- a/src/main/java/com/msdw/tms/entity/vo/StudentVo.java +++ b/src/main/java/com/msdw/tms/entity/vo/StudentVo.java @@ -5,6 +5,7 @@ import com.msdw.tms.entity.UserInfoEntity; import lombok.Data; import lombok.experimental.Accessors; +import javax.validation.constraints.Pattern; import java.util.List; /** @@ -19,6 +20,7 @@ public class StudentVo extends StudentEntity { //用户姓名 private String userName; //用户账号 + @Pattern(regexp = "^[0-9a-zA-Z]*$",message = "账号只能为数字或字母!") private String account; //密码 private String password;