Please enable JavaScript.
Coggle requires JavaScript to display documents.
Form Validation
Sử dụng Hibernate Validator, Custom Validation, Handle…
-
Custom Validation
-
tạo Custom Validation
// CourseCodeConstraintValidator: lớp chứa logic xác thực
ElementType: apply annotation cho method hoặc field
RetentionPolicy: giữ annotation trong bao lâu
import javax.validation.Payload;
Constraint (validatedBy = CourseCodeConstraintValidator.class)
Target ({ElementType.METHOD, ElementType.FIELD})
Retention(RetentionPolicy.RUNTIME)
public interface CourseCode {
public String value() default "LUV";
public String message () default "must start with LUV";
public Class<?>[] groups() default {};
public Class<? extends Payload>[] payload() default {};}
-
-
thêm Custom Validation vào class Customer
CourseCode
private String courseCode;
add getter/setter
-
-
-
-
number range
submit the form with an empty value but not throwing "is required"
-> replace "int" with "Integer"
-