@RequestMapping("register")
BaseResponse<JSONObject> register(@Valid UserDto userDto);
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class UserDto {
@NotEmpty(message = "用户名不能为空")
private String name;
@NotEmpty(message = "密码不能为空")
private String password;
@NotEmpty(message = "昵称不能为空")
private String nickName;
//手机号码
private String telephone;
//短信验证码
private String verityCode;
//微信公众号openId
private String openId;
//预登录令牌
private String preToken;
}
加了@Valid注解后就会校验对象的属性,节省if判断的冗余代码.