zoukankan      html  css  js  c++  java
  • Spring MVC 中使用 JSON 406错误

    错误信息

    15:05:42,695 DEBUG DispatcherServlet:865 - DispatcherServlet with name 'dispatcherServlet' processing POST request for [/demo/test/show1]
    15:05:42,704 DEBUG DefaultAnnotationHandlerMapping:140 - Mapping [/test/show1] to HandlerExecutionChain with handler [com.controller.SpringController@42bc2f82] and 1 interceptor
    15:05:42,725 DEBUG DefaultCorsProcessor:77 - Skip CORS processing: request is from same origin
    15:05:42,753 DEBUG HandlerMethodInvoker:177 - Invoking request handler method: public java.util.Map com.controller.SpringController.show1(com.entity.User)
    15:05:42,755 DEBUG AnnotationMethodHandlerExceptionResolver:133 - Resolving exception from handler [com.controller.SpringController@42bc2f82]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
    15:05:42,756 DEBUG ResponseStatusExceptionResolver:133 - Resolving exception from handler [com.controller.SpringController@42bc2f82]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
    15:05:42,757 DEBUG DefaultHandlerExceptionResolver:133 - Resolving exception from handler [com.controller.SpringController@42bc2f82]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
    15:05:42,757 DEBUG DispatcherServlet:1044 - Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
    15:05:42,757 DEBUG DispatcherServlet:1000 - Successfully completed request

    在SpringMVC配置文件上 添加<mvc:annotation-driven />,

    仅仅使用<context:component-scan base-package="com.controller" />,会忽略@ResponseBody注解,导致回传数据时,不能转换为json格式,406错误;

  • 相关阅读:
    玩转Visual Studio Editor篇
    .Net2.0的集合操作 What i know?
    Log文件压缩
    [转]比较高效地实现从两个不同数组中提取相同部分组成新的数组(只支持Int类型) [C#]
    Stream 和 Byte[]互操作
    net 2.0 中如何在线程引发的事件中控制forms controls
    C# 操作Word文档(转)
    利用Lucene.net搜索引擎进行多条件搜索的做法
    c# 添加图片水印,可以指定水印位置+生成缩略图
    SDN第一次作业
  • 原文地址:https://www.cnblogs.com/xiong233/p/6548600.html
Copyright © 2011-2022 走看看