From 490262cf816df9fe12facc240be2f7eb035efa83 Mon Sep 17 00:00:00 2001 From: zhaoqifeng Date: Wed, 29 Apr 2020 10:18:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A8=E5=8D=95=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/epmet/dto/form/StaffSubmitFromDTO.java | 9 +++++++-- .../main/java/com/epmet/controller/StaffController.java | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/StaffSubmitFromDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/StaffSubmitFromDTO.java index 0f368af813..f1b99c26a8 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/StaffSubmitFromDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/StaffSubmitFromDTO.java @@ -2,8 +2,11 @@ package com.epmet.dto.form; import lombok.Data; import lombok.NoArgsConstructor; +import org.hibernate.validator.constraints.Length; import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Pattern; import java.io.Serializable; import java.util.List; @@ -33,16 +36,18 @@ public class StaffSubmitFromDTO implements Serializable { * 姓名 */ @NotBlank(message = "姓名不能为空") + @Length(max = 5, message = "姓名不能超过5个字符") private String name; /** * 手机 */ @NotBlank(message = "手机号不能为空") + @Pattern(regexp = "^[1][3,4,5,6,7,8,9][0-9]{9}$", message = "手机号格式有误") private String mobile; /** * 性别 */ - @NotBlank(message = "性别不能为空") + @NotNull(message = "性别不能为空") private Integer gender; /** * 专兼职 @@ -52,7 +57,7 @@ public class StaffSubmitFromDTO implements Serializable { /** * 角色id列表 */ - @NotBlank(message = "角色不能为空") + @NotNull(message = "角色不能为空") private List roles; /** * 来源app(政府端:gov、居民端:resi、运营端:oper) diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/StaffController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/StaffController.java index 79da9b903b..1b8f109082 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/StaffController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/StaffController.java @@ -5,12 +5,14 @@ package com.epmet.controller; import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.dto.form.StaffInfoFromDTO; import com.epmet.dto.form.StaffSubmitFromDTO; import com.epmet.dto.form.StaffsInAgencyFromDTO; import com.epmet.dto.result.*; import com.epmet.service.StaffService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -81,6 +83,7 @@ public class StaffController { */ @PostMapping("addstaff") public Result addStaff(@LoginUser TokenDto tokenDto, @RequestBody StaffSubmitFromDTO fromDTO){ + ValidatorUtils.validateEntity(fromDTO); return staffService.addStaff(tokenDto, fromDTO); } @@ -92,6 +95,7 @@ public class StaffController { */ @PostMapping("editstaff") public Result editStaff(@LoginUser TokenDto tokenDto, @RequestBody StaffSubmitFromDTO fromDTO){ + ValidatorUtils.validateEntity(fromDTO); return staffService.editStaff(tokenDto, fromDTO); }