模版里提供的类中多了3个注解,其中@NotNull 是针对下面的参数不能为空,如果为空,会抛出 javax.validation.constraints.NotNull.message 而@Size 很容易理解
Documented @Constraint(validatedBy = { }) public @interface NotNull { String message() default "{javax.validation.constraints.NotNull.message
@Documented @Constraint(validatedBy = { }) public @interface NotNull { String message() default "{javax.validation.constraints.NotNull.message
它解析message的核心代码如下(比如此处message模版是{javax.validation.constraints.NotNull.message}为例): public abstract class
javax.validation.constraints.NotBlank.message = 不能为空 javax.validation.constraints.NotEmpty.message = 不能为空 javax.validation.constraints.NotNull.message
领取专属 10元无门槛券
手把手带您无忧上云