springmvc와 json 통합 설정 방법

8040 단어 SpringMvcjson
구성 방법 1
**1, 제3자 잭슨 패키지 가져오기, 잭슨-mapper-asl-1.9.7.jar와 jackson-core-asl-1.9.7.jar. 2. 스프링 프로필 추가**
 <mvc:annotation-driven/>

  
    <bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">  
        <property name="supportedMediaTypes">  
            <list>  
                <value>text/html;charset=UTF-8value>  
            list>  
        property>  
    bean>  

      
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">  
        <property name="messageConverters">  
            <list>  
                <ref bean="mappingJacksonHttpMessageConverter" />  
            list>  
        property>  
    bean> 

구성 시나리오 2(일반)
**1, 제3자의fastjson 패키지 가져오기,fastjson-1.34jar 2, Spring 프로필 추가:**
  <mvc:annotation-driven>
        <mvc:message-converters register-defaults="true">
            
            <bean id="fastJsonHttpMessageConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>application/json;charset=UTF-8value>
                    list>
                property>
            bean>
        mvc:message-converters>
    mvc:annotation-driven>

구성 시나리오 3
* 1. Jackson-annotations-*를 가져와야 합니다.jar,jackson-core-.jar,jackson-databind-.jar 2,spring에 설정 추가**
  <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" />
    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
        <property name="messageConverters">
            <list>
                <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                    <property name="supportedMediaTypes">
                        <list>
                            <value>text/html; charset=UTF-8value>
                            <value>application/json;charset=UTF-8value>
                        list>
                    property>
                bean>
                <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
                    <property name="supportedMediaTypes">
                        <list>
                            <value>text/html; charset=UTF-8value>
                            <value>application/json;charset=UTF-8value>
                        list>
                    property>
                bean>
            list>
        property>
    bean>
    :http://download.csdn.net/detail/l3922768721/9543001

좋은 웹페이지 즐겨찾기