<mvc:annotation-driven />注解详解
来源:互联网 发布:大乐斗门派心法数据 编辑:程序博客网 时间:2024/05/16 01:45
<mvc:annotation-driven /> 是一种简写形式,完全可以手动配置替代这种简写形式,简写形式可以让初学都快速应用默认配置方案。<mvc:annotation-driven /> 会自动注册DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean,是spring MVC为@Controllers分发请求所必须的。
并提供了:数据绑定支持,@NumberFormatannotation支持,@DateTimeFormat支持,@Valid支持,读写XML的支持(JAXB),读写JSON的支持(Jackson)。
后面,我们处理响应ajax请求时,就使用到了对json的支持。
后面,对action写JUnit单元测试时,要从spring IOC容器中取DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean,来完成测试,取的时候要知道是<mvc:annotation-driven />这一句注册的这两个bean。
<context:annotation-config>
declares support for general annotations such as @Required
, @Autowired
, @PostConstruct
, and so on.
<mvc:annotation-driven />
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 <context:annotation-config>
, but don't bother with <mvc:annotation-driven />
unless you want JSON support via Jackson.
当我们需要controller返回一个map的json对象时,可以设定<mvc:annotation-driven />,
同时设定<mvc:message-converters> 标签,设定字符集和json处理类,例如:
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
- <mvc:annotation-driven />注解详解
- spring-mvc注解(mvc:annotation-driven,JSON,配置详解)
- <mvc:annotation-driven />注解意义
- <mvc:annotation-driven />注解意义
- <mvc:annotation-driven />注解意义
- <mvc:annotation-driven />注解意义
- <mvc:annotation-driven />注解意义
- <mvc:annotation-driven />注解意义
- <mvc:annotation-driven />注解意义
- <mvc:annotation-driven/>注解意义
- <mvc:annotation-driven />注解意义
- <mvc:annotation-driven />注解意义
- <mvc:annotation-driven />注解意义
- <mvc:annotation-driven />注解意义
- <mvc:annotation-driven />注解意义
- <mvc:annotation-driven />注解意义
- <mvc:annotation-driven />注解意义
- <mvc:annotation-driven />注解意义
- mysql
- os学习中,遇到元组,原先随意看看的在认真学习一下了额
- 程序员面试金典——翻转子串
- ZOJ-3972 Beauty of Array
- Window操作系统注册表学习
- <mvc:annotation-driven />注解详解
- Linux网络服务参数配置说明及实战
- svn查看不到自己最近的log
- Mysql 性能优化随笔
- NYOJ
- Action类的三种创建方式
- 旋转数组的最小数(java)
- CSU OJ:1241 数字序列(并查集+思维)
- Eclipse安装插件时报No repository found containing...解决办法