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

  • 相关阅读:
    C语言qsort函数算法性能测试
    文档流 css中间float clear和布局
    EasyUI Combobox 默认设置
    碳化硅资料整理
    hdu 4864 Task(贪婪啊)
    tiny210——uboot移植Makefile文章分析
    规则字符串大小比较?
    js产生随机数
    四个好看的CSS样式表格
    request的setAttribute()怎么用的?
  • 原文地址:https://www.cnblogs.com/ylht/p/10202011.html
Copyright © 2011-2022 走看看