zoukankan      html  css  js  c++  java
  • (HttpMessageNotWritableException ) No converter found for return value of type xxxx

    最近在家没事儿,写写代码玩,用了Maven构建SSM项目,结果提示如下信息

    org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of type: class com.lcy.pojo.User
    【原因】找不到返回值类型的转换器,找了好久发现controller返回的是json格式数据

    【方案】在maven的pox.xml中只引入Json的依赖时,只引入了“jackson-core”;没有引入 “jackson-databind”,添加了依赖后问题解决了。
    【提示】当controller标记@ResponseBody后,会用解析器去解析Controller的返回值,解析器会去寻找SpringMvc中注册的HttpMeesageConverter接口的实现类,结果因为没有添加对应的依赖,所以
    就找不到Json类型的转换器了,添加依赖后就正常了。



    【正确的依赖】
    <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
            <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.8</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-core</artifactId>
                <version>2.9.8</version>
            </dependency>





    
    
  • 相关阅读:
    MVC模板页
    MVC Razor 语法(转)
    Code First 更新数据库结构
    mvc5 HTML Helper
    mvc5经典教程再补充。。
    mvc5入门,经典教程。。
    关于“以管理员身份运行”。。。
    windows8无脑式双系统安装教程(转)
    vs2010 无法连接到asp.net development server
    VMware虚拟机下安装RedHat Linux 9.0
  • 原文地址:https://www.cnblogs.com/ywtk/p/10490598.html
Copyright © 2011-2022 走看看