真的強

<mvc:annotation-driven />
是一種簡寫形式,完全可以手動配置替代這種簡寫形式,簡寫形式可以讓初學都快速應用默認配置方案。
<mvc:annotation-driven />
會自動註冊DefaultAnnotationHandlerMappingAnnotationMethodHandlerAdapter 兩個bean,
是spring MVC爲@Controllers分發請求所必須的。

並提供了:數據綁定支持,
@NumberFormatannotation支持,
@DateTimeFormat支持,
@Valid支持,讀寫XML的支持(JAXB),
讀寫JSON的支持(Jackson)。

我們在處理響應ajax請求時,就使用到了對json的支持。對action寫JUnit單元測試時,要從spring IOC容器中取DefaultAnnotationHandlerMapping與AnnotationMethodHandlerAdapter 兩個bean,來完成測試,取的時候要知道是這一句註冊的這兩個bean。

declares support for general annotations such as @Required, @Autowired, @PostConstruct, and so on.

is actually rather pointless. It declares explicit support for annotation-driven MVC controllers (i.e.@RequestMapping, @Controller, etc), even though support for those is the default behaviour.

My advice is to always declare , but don’t bother with unless you want JSON support via Jackson.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章