来源:http://blog.csdn.net/flashflight/article/details/13511679
spring从3.0开始提供一个HttpMessageConverter<T>接口,这个接口相当有用,spring可以针对Http报文头的ContentType来调用该类的默认实现类将HttpServletRequest转化成各种对象,如String,MultiValueMap,BufferedImage等类型,所以在做验证码或者上传文件时特别有用。spring默认加载该接口的四个默认实现类:StringHttpMessageConverter,ByteArrayHttpMessageConverter,SourceHttpMessageConverter,XmlAwareFormHttpMessageConverter.其余的例如处理json数据的默认类需要手动配置,具体配置例如:
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" p:messageConverters-ref="messageConverters"/>
<util:list id="messageConverters">
<bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter" />
</util:list>
*这里用到了p命名空间,具体资料可以自己查阅
<bean id="stringHttpMessageConverter"
class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>${html.contentType}</value>
</list>
</property>
</bean>
<bean id="byteArrayHttpMessageConverter"
class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
<bean id="resourceHttpMessageConverter"
class="org.springframework.http.converter.ResourceHttpMessageConverter" />
<bean id="sourceHttpMessageConverter"
class="org.springframework.http.converter.xml.SourceHttpMessageConverter" />
<bean id="allEncompassingFormHttpMessageConverter"
class="org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter" />
<bean id="mappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="objectMapper">
<bean class="org.codehaus.jackson.map.ObjectMapper">
<property name="serializationInclusion" value="NON_NULL" />
<property name="propertyNamingStrategy">
<bean
class="com.ita.kernel.strategy.UseFieldNameStrategy" />
</property>
</bean>
</property>
</bean>
<bean
class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="synchronizeOnSession" value="true" />
<property name="messageConverters">
<list>
<ref bean="stringHttpMessageConverter" />
<ref bean="byteArrayHttpMessageConverter" />
<ref bean="mappingJacksonHttpMessageConverter" />
<ref bean="resourceHttpMessageConverter" />
<ref bean="sourceHttpMessageConverter" />
<ref bean="allEncompassingFormHttpMessageConverter" />
</list>
</property>
</bean>
项目中spring-mvn有如上的配置,一直不是很清楚为什么这么配置??
相关推荐
<artifactId>springmvc</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <!-- 其他配置... --> </project> ``` 在这个示例中,`packaging`属性设置为`war`,表明这是一个Web应用...
<param-value>/WEB-INF/springmvc-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <listener> <listener-class>org.springframework.web.context....
<groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.x.x.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>...
<groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>4.3.23.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>...
<groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.x.y.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>...
<groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>5.3.23</version> </dependency> <!-- Servlet API --> <dependency> <groupId>javax.servlet</groupId> ...
<groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.x.x.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>...
该资源为SpringMVC中json转换所需要的Maven仓库,如果maven下载包的时候速度太慢,可以使用我的这个资源,把这个直接考到本地Maven仓库即可。 对应的Maven依赖如下: <dependency> <groupId>org.codehaus.jackson</...
<spring.version>4.0.2.RELEASE</spring.version> <mybatis.version>3.2.6</mybatis.version> <slf4j.version>1.7.7</slf4j.version> <log4j.version>1.2.17</log4j.version> </properties> <dependencies> <!...
<groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.x.x.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>...
<groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.x.x.RELEASE</version> </dependency> <!-- SpringMVC 相关依赖 --> <dependency> <groupId>org.spring...
<groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>5.x.y.RELEASE</version> </dependency> <!-- Mybatis --> <dependency> <groupId>org.mybatis</groupId> ...
<groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.x.x.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>...
<groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.x.x.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>...
<groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.x.x.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>...
<groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.x.x.RELEASE</version> </dependency> <!-- Spring MVC --> <dependency> <groupId>org.springframework</...
* `cn.springmvc.dao`:存放 Spring 与 MyBatis 连接接口 * `cn.springmvc.service`:存放服务接口 * `cn.springmvc.service.impl`:存放服务接口的实现 * `cn.springmvc.controller`:存放控制层 Controller 在 `...
<groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.3.x</version> </dependency> <!-- Spring MVC --> <dependency> <groupId>org.springframework</groupId> ...
<groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.x.x.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>...
<groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.x.x.RELEASE</version> </dependency> ``` SpringMVC的依赖: ```xml <dependency> <groupId>org.spring...