1. 程式人生 > >SpringMvc之 mvc:annotation-driven標籤

SpringMvc之 mvc:annotation-driven標籤

在我們要完成比較複雜的資料型別轉換時(比如:頁面輸入的String型別轉換成Date型別,將頁面的String型別轉換成封裝成一個物件時)需要在SpringMvc的配置檔案中新增<mvc:annotation-driven/>標籤。

     那<mvc:annotation-driven/>標籤的作用是什麼呢?

    作用1: 在SpringMvc配置檔案中,使用<mvc:annotation-driven/>標籤,改標籤可以j簡化SpringMvc的相關配置,自動註冊RequestMappingHandlerMapping與RquestMappingHandlerAdapter兩個Bean,這是SpringMVC 為@Controllers註解分發請求所必需的。(在實際開發過程中要新增上<mvc:annotation-driven/>標籤)

     作用2:<mvc:annotation-driven/>標籤還會註冊一個預設的ConversionService,即FormattingConversionServiceFactoryBean,以滿足大多數型別轉換的需求。

如果哪裡有總結的不對,望及時指出。