zoukankan      html  css  js  c++  java
  • SSM报错:No converter found for return value of type: class java.util.ArrayList at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverter

    我使用的是SSM框架,是在编写测试RESTFUL接口的时候出现,

    @RequestMapping(value = "/selectAll", method = RequestMethod.GET)
        @ResponseBody
        public ResponseEntity<List<User>> selectAll() {
            List<User> users = this.userService.selectAll();
            if (null != users && users.size() > 0) {
                return ResponseEntity.ok(users);
            }
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
        }

    代码不是非常严谨,只是做测试。

    访问:http://localhost:8081/selectAll

    错误:

    No converter found for return value of type: class java.util.ArrayList at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:187) at org.s

    原因:这是因为springmvc默认是没有对象转换成json的转换器的,需要手动添加jackson依赖。

    解决:添加相关依赖

    <!--jacson支持json-->
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-core</artifactId>
                <version>2.5.4</version>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>2.5.4</version>
            </dependency>

    成功解决:

    [{"username":"admin","password":"admin"},{"username":"zhanxuewei","password":"123456"}]

    参考:https://www.cnblogs.com/hafiz/p/5812873.html

  • 相关阅读:
    《大话设计模式》读书笔记
    设计模式个人笔记
    多线程的单元测试工具
    设计模式六大原则
    时间复杂度和空间复杂度(转)
    排序算法笔记
    《人月神话》读书笔记
    微信公众号开发踩坑记录(二)
    微信公众号开发踩坑记录
    全栈工程师之路
  • 原文地址:https://www.cnblogs.com/ylht/p/10202011.html
Copyright © 2011-2022 走看看