Mapping the request body with the @RequestBody annotation

来源:互联网 发布:商家联盟管理系统源码 编辑:程序博客网 时间:2024/06/18 08:21
  1. @RequestBody概念:

    a method parameter should be bound to the value of the HTTP request body(方法参数名要与请求体的json数据的参数名对应)

  2. You convert the request body to the method argument by using an HttpMessageConverter

    转换器配置:

<bean        class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">        <property name="messageConverters">            <list>                <ref bean="jsonHttpMessageConverter" />            </list>        </property>    </bean>    <bean id="jsonHttpMessageConverter"        class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">         <property name="supportedMediaTypes">            <list>                <value>application/json;charset=UTF-8</value>            </list>        </property>     </bean>
原创粉丝点击