@Test public void normal() { MockForm form = new MockForm(); form.setEmail("zxc@msun.com"); form.setPassword("hello1234"); ValidationResult valid = FormValidator.isValid(form); System.out.println(valid); assertTrue(valid.isValid()); assertFalse(valid.isFieldError("email")); }
public static ValidationResult isValid(Form form) { if (form == null) { throw new IllegalAddException("Arugment cannot be null"); } Class<? extends Object> type = form.getClass(); String key = type.getName(); ValidatorContianer contianer = cached.get(key); if (contianer == null) { contianer = new ValidatorContianer(); cached.put(key, contianer); } ValidationResult result = new ValidationResult(); for (Field filed : type.getDeclaredFields()) { validFiled(form, filed, contianer, result); } return result; }
FormValidator { public static ValidationResult isValid(Form form) { if (form == null) { throw new IllegalAddException("Arugment cannot be null"); } Class<? extends Object> type = form.getClass(); String key = type.getName(); ValidatorContianer contianer = cached.get(key); if (contianer == null) { contianer = new ValidatorContianer(); cached.put(key, contianer); } ValidationResult result = new ValidationResult(); for (Field filed : type.getDeclaredFields()) { validFiled(form, filed, contianer, result); } return result; } }
FormValidator { public static ValidationResult isValid(Form form) { if (form == null) { throw new IllegalAddException("Arugment cannot be null"); } Class<? extends Object> type = form.getClass(); String key = type.getName(); ValidatorContianer contianer = cached.get(key); if (contianer == null) { contianer = new ValidatorContianer(); cached.put(key, contianer); } ValidationResult result = new ValidationResult(); for (Field filed : type.getDeclaredFields()) { validFiled(form, filed, contianer, result); } return result; }  }
FormValidator { public static ValidationResult isValid(Form form) { if (form == null) { throw new IllegalAddException("Arugment cannot be null"); } Class<? extends Object> type = form.getClass(); String key = type.getName(); ValidatorContianer contianer = cached.get(key); if (contianer == null) { contianer = new ValidatorContianer(); cached.put(key, contianer); } ValidationResult result = new ValidationResult(); for (Field filed : type.getDeclaredFields()) { validFiled(form, filed, contianer, result); } return result; }  static ValidationResult isValid(Form form); static ValidationResult isValid(String fieldKey, String displayName, Object value, String... validatorIds); }
FormValidator { public static ValidationResult isValid(Form form) { if (form == null) { throw new IllegalAddException("Arugment cannot be null"); } Class<? extends Object> type = form.getClass(); String key = type.getName(); ValidatorContianer contianer = cached.get(key); if (contianer == null) { contianer = new ValidatorContianer(); cached.put(key, contianer); } ValidationResult result = new ValidationResult(); for (Field filed : type.getDeclaredFields()) { validFiled(form, filed, contianer, result); } return result; }  static ValidationResult isValid(Form form); static ValidationResult isValid(String fieldKey, String displayName, Object value, String... validatorIds);  }