org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supported或其他Content type不支持处理
很久没从头到尾搭框架,今天搭的过程中,springmvc controller方法入参用@RequestBody自动绑定参数时一直提示各种 not supported
排查问题有两个解决路径:
1)使用post协议提交时,请检查Content type类型,如:
$.ajax({
type: "POST",
contentType: "application/json;charset=UTF-8",
url: "/reg",
data: JSON.stringify(data.field),
dataType: 'json',
success: function(result) {
if(result.code == 0) {
layer.msg('注册成功!');
} else {
layer.msg(result.msg);
}
}
});
请检查上方contentType类型,如果想用springmvc @RequestBody注解做提交json字符串自动绑定到pojo入参时,类型需要是"application/json;charset=UTF-8",否则会抛"not supported"异常。
2)缺少jackson-databind jar包
这个好办,把maven或gradle的坐标加上就好,如下:
maven:
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.8.1</version>
</dependency>
gradle:
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.8.1'
然后controller直接这么用就好了:
@RequestMapping(value = "/reg", method = RequestMethod.POST)
@ResponseBody
public ResponseVo reg(@RequestBody user u) throws Exception {
//其他crud逻辑
}
org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supported或其他Content type不支持处理的更多相关文章
- org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supported
最后找到我的问题,springmvc配置文件中没加 <mvc:annotation-driven/> java代码: @RequestMapping(value="/reques ...
- Content type 'application/json;charset=UTF-8' not supported异常的解决过程
首先说一下当时的场景,其实就是一个很简单的添加操作,后台传递的值是json格式的,如下图 ,后台对应的实体类, @Data @EqualsAndHashCode(callSuper = false) ...
- SpringMVC在使用JSON时报错信息为:Content type 'application/json;charset=UTF-8' not supported
直接原因是:我的(maven)项目parent父工程pom.xml缺少必要的三个jar包依赖坐标. 解决方法是:在web子模块的pom.xml里面添加springMVC使用JSON实现AJAX请求. ...
- ajax使用向Spring MVC发送JSON数据出现 org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported错误
ajax使用向Spring MVC发送JSON数据时,后端Controller在接受JSON数据时报org.springframework.web.HttpMediaTypeNotSupportedE ...
- org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'multipart/form-data;boundary=----WebKitFormBoundaryRAYPKeHKTYSNdzc1;charset=UTF-8' not supported
原文:https://www.cnblogs.com/yueli/p/7552888.html 最近同事在做一个图片上传功能.在入参 body 中同时传入文件和其它基本信息结果出现如题异常.在此记录下 ...
- jmeter报"msg":"Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported"的解决方法
1.报"msg":"Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supporte ...
- Jmeter发送post请求报错Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
常识普及: Content-type,在Request Headers里面,告诉服务器,我们发送的请求信息格式,在JMeter中,信息头存储在信息头管理器中,所以在做接口测试的时候,我们维护Conte ...
- Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported告诉你,你的请求头是application/x- ...
- 接入WxPusher微信推送服务出现错误:Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
背景 使用WxPusher微信推送服务 ,可以及时的将服务的一些运行异常信息,发送到自己的微信上,方便了解服务的运行状态(PS:这个服务是免费的). 你可以在这里看到WxPusher微信推送服务的接入 ...
随机推荐
- 洛谷P2756 飞行员配对方案问题(二分图匹配)
传送门 一个基础的二分图匹配(虽然今天才学会) 因为不会匈牙利算法只好用网络流做 先新建一个超级源和超级汇,源往所有左边的点连边,所有右边的点往汇连边 然后跑一边最大流就好了 顺便记录一下匹配到谁就好 ...
- 【spring boot】FilterRegistrationBean介绍
前言 以往的javaee配置过滤器是在web.xml中配置的,如下代码 <filter> <filter-name>TestFilter</filter-name> ...
- 【离散数学】 SDUT OJ 1.1联结词真值运算
1.1联结词真值运算 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Problem Description 已知命题变元p和 ...
- Ajax轮询 select循环输出
弹出层 <include file="Pub:header"/> <style> .del{color:red} .addname{color:#337ab ...
- JS 只创建一个元素
//判断有没有这个元素<div id="div"> if(my$("div").firstElementChild){ console.log(&q ...
- @ApiParam @PathVariable @RequestParam三者区别
转载:https://www.cnblogs.com/xu-lei/p/7803062.html @ApiParam @PathVariable @RequestParam三者区别 1.@ApiPar ...
- Takari Extensions for Apache Maven (TEAM)
http://takari.io/book/index.html TEAM stands for the Takari Extensions for Apache Maven. TEAM is a c ...
- URL 地址传中文,转码
地址传中文,转码 http://community.csdn.net/Expert/topic/4541/4541877.xml?temp=.57688541.设置web.config文件.<s ...
- BZOJ - 3757 树上莫队解决离线路径问题 & 学习心得
题意:给你一棵树,求u,v最短路径的XXX(本题是统计权值种类) 今天课上摸鱼学了一种有意思的处理路径方式(其实是链式块状树翻车了看别的),据说实际运行跑的比XX记者还快 大概就是像序列莫队那样 首先 ...
- Apache Shiro(六)-基于URL配置权限
数据库 先准备数据库啦. DROP DATABASE IF EXISTS shiro; CREATE DATABASE shiro DEFAULT CHARACTER SET utf8; USE sh ...