MCPcopy Create free account
hub / github.com/castello/spring_basic / GlobalValidator

Class GlobalValidator

ch2/GlobalValidator.java:7–32  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5import org.springframework.validation.Validator;
6
7public class GlobalValidator implements Validator {
8 @Override
9 public boolean supports(Class<?> clazz) {
10// return User.class.equals(clazz); // 검증하려는 객체가 User타입인지 확인
11 return User.class.isAssignableFrom(clazz); // clazz가 User 또는 그 자손인지 확인
12 }
13
14 @Override
15 public void validate(Object target, Errors errors) {
16 System.out.println("GlobalValidator.validate() is called");
17
18 User user = (User)target;
19
20 String id = user.getId();
21
22// if(id==null || "".equals(id.trim())) {
23// errors.rejectValue("id", "required");
24// }
25 ValidationUtils.rejectIfEmptyOrWhitespace(errors, "id", "required");
26 ValidationUtils.rejectIfEmptyOrWhitespace(errors, "pwd", "required");
27
28 if(id==null || id.length() < 5 || id.length() > 12) {
29 errors.rejectValue("id", "invalidLength", new String[]{"5", "12"}, null);
30 }
31 }
32}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected