spring+mvc_返回json数据 406

来源:互联网 发布:nodejs 运行sql文件 编辑:程序博客网 时间:2024/06/05 18:08
1 .选择jar包不正确
2.servlet.xml 配置文件 问题 :


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:context="http://www.springframework.org/schema/context"
 xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="
    http://www.springframework.org/schema/beans    
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
 <context:component-scan base-package="com.springmvc.controller" />

 <bean
  class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">

  <property name="mediaTypes">
   <map>
    <entry key="atom" value="application/atom+xml" />
    <entry key="html" value="text/html" />
    <entry key="json" value="application/json" />
   </map>
  </property>

  <property name="viewResolvers">
   <list>
    <bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
    <bean
     class="org.springframework.web.servlet.view.InternalResourceViewResolver">
     <property name="prefix" value="/WEB-INF/pages/" />
     <property name="suffix" value=".jsp" />
    </bean>
   </list>
  </property>

  <property name="defaultViews">
   <list>
    <bean
     class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
   </list>
  </property>

 </bean>
 <mvc:annotation-driven />

</beans>


0 0
原创粉丝点击