@Data
public class UserRegistVo {
@NotEmpty(message = "用户名必须提交")
@Length(min = 6,max = 18,message = "用户名必须是6~18位字符")
private String userName;
@NotEmpty(message = "密码必须填写")
@Length(min = 6,max = 18,message = "密码必须是6~18位字符")
private String password;
@NotEmpty(message = "手机号必须填写")
@Pattern(regexp = "^[1][0-9_-]{10}$",message = "手机号格式不正确")
private String phone;
@NotEmpty(message = "验证码格式必须填写")
private String code;
}
@RequestMapping("/regist")
public String regist(@Valid UserRegistVo userRegistVo, BindingResult result, RedirectAttributes redirectAttributes) {
/**
* 前置校验
* */
if (result.hasErrors()) {
Map<String, String> errorMap = result.getFieldErrors().stream().collect(Collectors.toMap(FieldError::getField, DefaultMessageSourceResolvable::getDefaultMessage));
//model.addAttribute("errors", errorMap);
redirectAttributes.addFlashAttribute("errors", errorMap);
return "redirect:http://auth.gulimall.com/reg ";
}
return "redirect:http://auth.gulimall.com";
}