@NotNull
为不可为空
@NotNull(message = "primary is not null",groups = {Update.class})
/* 分组校验 */
public @interface Create {}
/* 分组校验 */
public @interface Update {}
groups = {Update.class}
groups是验证分组,比如我有的验证只有更新的时候做,有的只有添加的时候做
message =“primary is not null”
message是信息显示,比如在我更新的时候为空时,返回 “primary is not null”
此时controller应该要加上@Valid ,否则不会验证
@RequestMapping(value = "/test")
public Map<String, Object> test(@Valid @RequestBody test test) {
return null;
}