@RestController
public class UserController {
@PostMapping("/user/getUser")
//这里加上@Valid
public User getUser(@Valid @RequestBody Page<User> userPamas){
User user=new User();
user.setName(userPamas.getObj().getName());
user.setAge(30);
user.setSex("男");
return user;
}
@Data
public class Page<T> {
private Integer pageSize;
private Integer pageNum;
@Valid //这里很关键
private T obj;
}
@Data
public class User {
@NotEmpty(message = "用户名不能为空")
private String name;
private int age;
private String sex;
private Integer id;
@Pattern(regexp = "//d{11}",message = "手机号格式不正确")
private String phone;
}