Spring MVC:报错No converter found for return value of type

来源:互联网 发布:赛酷ocr软件 编辑:程序博客网 时间:2024/06/05 03:14

问题描述:

请求数据返回时报错No converter found for return value of type


原因:

不能将map转换为json传输


解决方案:

引入json相关包:

<dependency>    <groupId>org.codehaus.jackson</groupId>    <artifactId>jackson-core-asl</artifactId>    <version>1.9.10</version></dependency><dependency>    <groupId>org.codehaus.jackson</groupId>    <artifactId>jackson-mapper-asl</artifactId>    <version>1.9.10</version></dependency><dependency>    <groupId>com.fasterxml.jackson.core</groupId>    <artifactId>jackson-annotations</artifactId>    <version>2.2.3</version></dependency><dependency>    <groupId>com.fasterxml.jackson.core</groupId>    <artifactId>jackson-core</artifactId>    <version>2.2.3</version></dependency><dependency>    <groupId>com.fasterxml.jackson.core</groupId>    <artifactId>jackson-databind</artifactId>    <version>2.2.3</version></dependency><dependency>    <groupId>net.sf.json-lib</groupId>    <artifactId>json-lib</artifactId>    <version>2.2.3</version>    <classifier>jdk15</classifier></dependency>

修改applicationContext.xml文件:

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


为响应返回类添加setter方法

阅读全文
0 0
原创粉丝点击