我使用bean验证注释定义了以下类。
@Data
@Entity
public class Contact{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Min(value=7,message = "Mobile number must have at least 7 digits")
private int contactNumber;
@Min(value=7,message = "Mobile number must have at least 7 digits")
private int mobileNumber;
}
但是,当我将以下JSON发布到端点http://localhost:8080/contacts
时,它不会抛出约束违例异常。这篇文章很成功。
{
"contactNumber": 77,
"mobileNumber" : 77
}
那么如何修复此验证?