No Converter found for return value of Type:class Java.util.HashMap
When using @ResponseBody to return JSON in SPRINGMVC, you need to manually add the Jackson dependency! Maven Add:
<Dependency><Groupid>com.fasterxml.jackson.core</Groupid><Artifactid>jackson-core</artifactid> < version>2.4.3</version></dependency>< dependency> <groupId> Com.fasterxml.jackson.core</groupid> <artifactid>jackson-databind</< Span class= "Hljs-name" >artifactid> <version>2.4.3</version></ Dependency>
``
You can do it without MAVEN, Springmvc-servlet.xml is configured as follows
<!--start Springmvc annotation Driver<Mvc:annotation-driven/><!--return JSON method one needs to import Fastjson.jar package--<Mvc:annotation-driven><Mvc:message-convertersregister-defaults="False" ><!--avoid IE when performing Ajax, return JSON appears download file--<BeanId="Fastjsonhttpmessageconverter"class="Com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter" ><PropertyName="Supportedmediatypes" ><List><!--here the order can not be reversed, must first write text/html, or IE under the download prompt<Value>text/html;charset=utf-8</Value><Value>application/json;charset=utf-8</Value></List></Property></Bean></Mvc:message-converters></Mvc:annotation-driven><!--return JSON method two need to import jackson-annotations.jar,jackson-core.jar,jackson-databind.jar--><!--<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-8</value> <value>application/json;charset=UTF-8</value> </list> </property > </bean> <bean 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> </list> </property> </bean>-->
controller代码:@RequestMapping(value="/json")@ResponseBodypublic Object getJson(){ Map<String, Object> map=new HashMap<String, Object>(); map.put("fd", "郝鹏"); return map;}
You can return the map to the front end, such as the AJAX request on the front, and return data such as DATA.FD to Shangpeng
When using @ResponseBody to return JSON in SPRINGMVC, you need to manually add the Jackson dependency