Browse Source

表单验证

master
zhaoqifeng 5 years ago
parent
commit
490262cf81
  1. 9
      epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/StaffSubmitFromDTO.java
  2. 4
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/StaffController.java

9
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<String> roles;
/**
* 来源app(政府端:gov居民端:resi运营端:oper)

4
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);
}

Loading…
Cancel
Save