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

Class UserValidator

ch2/UserValidator.java:8–33  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected