返回hashmap错误
Type Exception Report Message No converter found for return value of type: class java.util.HashMap Description The server encountered an unexpected condition that prevented it from fulfilling the request. Exception org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of type: class java.util.HashMap org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:238) org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:181) org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:82) org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:124) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:888) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793) org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) javax.servlet.http.HttpServlet.service(HttpServlet.java:634) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) Note The full stack trace of the root cause is available in the server logs.
返回String正常,因为后面ssm校园管理项目,我看老师也没做什么配置,但是返回hashmap也能在前端显示,而且我想问的是为什么我这里返回hashmap有问题.,在校园店铺管理没问题呢,还有@ResponseBody,返回页面上的好像就是json字符串呀,
正在回答
同学jar包下载下来了吗?
清除一下idea的缓存呢?
如果我的回答解决了你的疑惑,请采纳,祝学习愉快~
同学你好!
老师在本地测试你的代码是没有问题的呢
请问同学的pom文件中是不是没有引入json的jar包呢,建议同学添加一下
<dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.9.9</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.9.9</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>2.9.9</version> </dependency>
如果我的回答解决了你的疑惑,请采纳,祝学习愉快~
@RequestMapping("/get")
@ResponseBody
private Map<String, Object> get() {
Map<String, Object> modelMap = new HashMap<String, Object>();
modelMap.put("count", 123);
modelMap.put("success", true);
return modelMap;
}
@GetMapping("/newget")
@ResponseBody
private String newGet() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("count", 123);
map.put("success", true);
map.toString();
return map.toString();
}
newGet返回String是没问题的
相似问题
登录后可查看更多问答,登录/注册
- 参与学习 人
- 提交作业 323 份
- 解答问题 8263 个
本阶段将带你学习主流框架SSM,以及SpringBoot ,打通成为Java工程师的最后一公里!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星