SpringMVC @RequestBody 自动转json Http415错误
转自: http://blog.csdn.net/tiantiandjava/article/details/46125141
项目中想用@RequestBody直接接收json串转成对象
网上查了使用方法,看着非常简单,不过经过测试很快发现页面直接报415错误。
- <body>
- <h1>HTTP Status 415 - </h1>
- <HR size="1" noshade="noshade">
- <p>
- <b>type</b> Status report
- </p>
- <p>
- <b>message</b>
- <u></u>
- </p>
- <p>
- <b>description</b>
- <u>The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.</u>
- </p>
- <HR size="1" noshade="noshade">
- <h3>Apache Tomcat/6.0.41</h3>
- </body>
经过一通查,多半的解决方法实说header里的 Content-Type 一定 application/json
但是问题依然没有解决。
最后在《Spring in Action》里找到一个信息
有两个前提条件:
The request’sContent-Typeheader
must be set toapplication/json.
The JacksonJSONlibrary
must be available on the application’s classpath.
我满足了第一个,所以在classpath中添加了一个jar。问题解决了。
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- <version>2.5.3</version>
- </dependency>
所以如果大家遇到了同样的问题,可以先排除一下这两个因素。
------------------------------
还有一种情况,在以上两个条件都满足的情况下,还是报同样的错误。
在springmvc的配置文件中必须有:
- <!-- 默认的注解映射的支持 -->
- <mvc:annotation-driven />
如果没有这个配置也是会报这个错的!
为什么会引入jackson-databind包呢,因为默认的配置会用到:
- com.fasterxml.jackson.databind.ObjectMapper
SpringMVC @RequestBody 自动转json Http415错误的更多相关文章
- Spring MVC @RequestBody自动转JSON HTTP415错误解决方法
转自:http://blog.csdn.net/tiantiandjava/article/details/46125141 项目中想用@RequestBody直接接收json串转成对象 网上查了使用 ...
- springmvc @responseBody自动打包json出现错误(外键查询死循环)问题
在外键字段的get方法上加入@JsonIgnore
- SpringMVC中出现" 400 Bad Request "错误(用@ResponseBody处理ajax传过来的json数据转成bean)的解决方法
最近angularjs post到后台 400一头雾水 没有任何错误. 最后发现好文,感谢作者 SpringMVC中出现" 400 Bad Request "错误(用@Respon ...
- 解决ajax请求(SpringMVC后台)响应415/400/405错误
解决ajax请求(SpringMVC后台)响应415/400/405错误 后端代码 bean public class user { private String username; private ...
- SpringMVC 中整合之JSON、XML
每次看到好的博客我就想好好的整理起来,便于后面自己复习,同时也共享给网络上的伙伴们! 博客地址: springMVC整合Jaxb2.xStream: http://www.cnblogs.com/h ...
- 扩展SpringMVC以支持绑定JSON格式的请求参数
此方案是把请求参数(JSON字符串)绑定到java对象,,@RequestBody是绑定内容体到java对象的. 问题描述: <span style="font-size: x-sma ...
- java框架之SpringBoot(5)-SpringMVC的自动配置
本篇文章内容详细可参考官方文档第 29 节. SpringMVC介绍 SpringBoot 非常适合 Web 应用程序开发.可以使用嵌入式 Tomcat,Jetty,Undertow 或 Netty ...
- SpringMVC札集(07)——JSON数据
自定义View系列教程00–推翻自己和过往,重学自定义View 自定义View系列教程01–常用工具介绍 自定义View系列教程02–onMeasure源码详尽分析 自定义View系列教程03–onL ...
- 7、springmvc的自动配置
1.springmvc的自动配置 文档:https://docs.spring.io/spring-boot/docs/2.1.1.RELEASE/reference/htmlsingle/#boot ...
随机推荐
- python数据类型,int,str,bool
一,python中的int() int在python中主要用来运算,对字符串的转化,用int(str)表示,并且需要str.isdigit为真. 在int()中二进制的转换如下: #bit_lengt ...
- Azure VNet介绍
Azure VNet的介绍 VNet是Azure云中逻辑隔离的虚拟网络.它包含两个含义: Azure的用户可以在VNet中创建自己的各种资源,感觉想自己的数据中心中一样; 在一个VNet中创建的资源和 ...
- 接口方式[推荐]/动态SQL语句
MVC目录结构: Src -- com.shxt.servlet[控制层] --com.shxt.service[业务逻辑层] --com.shxt.model[实体Bean,用来承载数据] --co ...
- java代码equals方法
package com.bc; public class Test_6 { // 我们知道java中的每个类都继承自Object类,equals是Object方法之一 String name; int ...
- linux参数之max_map_count
“This file contains the maximum number of memory map areas a process may have. Memory map areas are ...
- ajax补充FormData
一.回顾上节知识点 1.什么是json字符串? 轻量级的数据交换格式 2.定时器:关于setTimeout setTimeout(foo,3000) # 3000表示3秒,foo表示一个函数,3秒后 ...
- 类型:Oracle;问题:oracle 查询表详细信息;结果:oracle查询表信息(索引,外键,列等)
oracle查询表信息(索引,外键,列等) oracle中查询表的信息,包括表名,字段名,字段类型,主键,外键唯一性约束信息,索引信息查询SQL如下,希望对大家有所帮助: 1.查询出所有的用户表sel ...
- 【Android 多媒体应用】使用 TTS
import java.util.Locale; import android.app.Activity; import android.os.Bundle; import android.speec ...
- 根据URL下载文件
commons-io 包中已经封装好了,直接可以使用 一.添加依赖 <dependency> <groupId>org.apache.commons</groupId&g ...
- springmvc 注解式开发 解决中文乱码问题