微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

第八讲:springmvc中ajax、json的处理

1、使用HttpServletResponse处理---不需要配置解析器(ajax)

2、springmvc处理json数据

 a) 导入jar包

  

 b) 配置json转换器

<bean id="stringConverter"
        class="org.springframework.http.converter.StringHttpMessageConverter">
        <property name="supportedMediaTypes">
            <list>
                <value>text/plain;charset=UTF-8</value>
            </list>
        </property>
    </bean>
    <bean id="jsonConverter"
        class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
    </bean>
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="messageConverters">
            <list>
                <ref bean="stringConverter"/>
                <ref bean="jsonConverter"/>
            </list>
        </property>
    </bean>

  c) Controller代码

 

 

 补加

 

 

 

  

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐