<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <mvc:annotation-driven /> </beans>
其實<mvc:annotation-driven /> 是一種簡寫形式,完全可以手動配置替代這種簡寫形式,簡寫形式可以讓初學都快速應用默認配置方案。
<mvc:annotation-driven /> 會自動註冊一個RequestMappingHandlerMapping,一個與之對應的處理器適配器RequestMappingHandlerAdapter和一個處理異常處理器。支持處理controller中註解了請求的方法(比如@RequestMapping、@ExceptionHandler等等)--來自官方文檔
除此之外,並且提供了數據支持:
- 支持格式化數字字段(formatting Number fields)通過使用@NumberFormat 註解
- 支持格式化日期、日曆、Long表示的毫秒、joda Time 字段, 使用@DateTimeFormat註解
- 支持控制器的輸入校驗(validating @Controller inputs with @Valid)通過使用@Valid。前提是在當前項目中加入了jsr303類庫
- 支持從@RequestMapping或@ExceptionHandler的方法同時註解了@RequestBody的方法參數、註解了@ResponseBody方法返回。裝配某些HttpMessageConverter請求信息轉化類。
裝配了以下9個HttpMessageConverter