什麼是攔截器?有什麼用?spring mvc如何定義攔截器?
what:
類似於filter的一個對象,用於預處理以及後處理處理器(控制器)。
how:
新建class實現HandlerInterceptor重寫三個方法preHandlerpostHandlerafterCompletionspringmvc.xml中配置攔截器
2 spring mvc中如何做表單數據校驗?
環境搭建
1,springmvc.xml中配置一個validator
2,<mvc:annotation-driven validator="validator"/>;
給Entity添加校驗規則
@NotEmpty
@Length
...
用BindingResult 緊接着entity之後來接收錯誤信息。
test(User user,BindingResult rs)