2012-10-20 27 views
0

我想使用使用註釋春季3.0驗證。 http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/validation.html#core-convert如何檢測Spring驗證是否通過?

我的代碼看起來像文檔中:

@Controller 
public class MyController { 

    @InitBinder 
    protected void initBinder(WebDataBinder binder) { 
     binder.setValidator(new FooValidator()); 
    } 

    @RequestMapping("/foo", method=RequestMethod.POST) 
    public void processFoo(@Valid Foo foo) { ... } 

} 

public class PersonValidator implements Validator { 

    /** 
    * This Validator validates just Person instances 
    */ 
    public boolean supports(Class clazz) { 
    return Person.class.equals(clazz); 
    } 

public void validate(Object obj, Errors e) { 
    ValidationUtils.rejectIfEmpty(e, "name", "name.empty"); 
} 

}

如何我在RequestMapping方法告訴我們,如果驗證通過與否?

回答

0

啊哈...這是微不足道的...只是想通了,我有我的RequestMapping一個BindingResult參數具有hasErrors()方法。

相關問題