0

控制器中代码

@RequestMapping(value = "/listArea",method = RequestMethod.GET)
    @ResponseBody
    private Map<String,Object> listArea(){
        Map<String,Object> modelMap = new HashMap<>();

        List<Area> list = areaService.getAreaList();
        modelMap.put("rows", list);
        modelMap.put("total", list.size());
        return modelMap;
    }

xml中的使用了这个
<mvc:annotation-driven/>

pom.xml引入下列依赖

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.9.8</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.9.0</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>

访问接口时报错

WARN org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver - Resolved [org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of type: class java.util.HashMap]
DEBUG org.springframework.web.servlet.DispatcherServlet - Completed 500 INTERNAL_SERVER_ERROR
2 个回答
0

1,返回值类型写错了,因为@responsebody返回的数据是JSON格式,但是JSON格式类型是String,所以你的返回值应该是String而不是Map
2,还有方法修饰词应改为public而不是private

0

缺少Jackson的绑定依赖,加上这个依赖试试

  <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>${jackson.version}</version>
  </dependency>

如果还不行参考这个链接的做法,再加个配置:解决java.lang.IllegalArgumentException: No converter found for return value of

撰写答案

推广链接