很久没从头到尾搭框架,今天搭的过程中,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不支持处理的更多相关文章

  1. org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supported

    最后找到我的问题,springmvc配置文件中没加 <mvc:annotation-driven/> java代码: @RequestMapping(value="/reques ...

  2. Content type 'application/json;charset=UTF-8' not supported异常的解决过程

    首先说一下当时的场景,其实就是一个很简单的添加操作,后台传递的值是json格式的,如下图 ,后台对应的实体类, @Data @EqualsAndHashCode(callSuper = false) ...

  3. SpringMVC在使用JSON时报错信息为:Content type 'application/json;charset=UTF-8' not supported

    直接原因是:我的(maven)项目parent父工程pom.xml缺少必要的三个jar包依赖坐标. 解决方法是:在web子模块的pom.xml里面添加springMVC使用JSON实现AJAX请求. ...

  4. 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 ...

  5. 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 中同时传入文件和其它基本信息结果出现如题异常.在此记录下 ...

  6. 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 ...

  7. Jmeter发送post请求报错Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported

    常识普及: Content-type,在Request Headers里面,告诉服务器,我们发送的请求信息格式,在JMeter中,信息头存储在信息头管理器中,所以在做接口测试的时候,我们维护Conte ...

  8. 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- ...

  9. 接入WxPusher微信推送服务出现错误:Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported

    背景 使用WxPusher微信推送服务 ,可以及时的将服务的一些运行异常信息,发送到自己的微信上,方便了解服务的运行状态(PS:这个服务是免费的). 你可以在这里看到WxPusher微信推送服务的接入 ...

随机推荐

  1. Struts、Hibernate和Spring的整合

    Spring整合Hibernate Spring以其开放性,能与大部分ORM框架良好的整合.这样Spring就能轻松地使用ORM. Spring提供了DAO支持,DA0组件是应用的持久层访问的重要组件 ...

  2. 对于Discuz 及PHP的一点个人感受

    首先我知道PHP是一种编程语言,PHP这玩意灵活性够了,但总是让人感觉写出来的代码让人如坠五里雾中,一会一个变量,$什么,一会又一个$.对于它是什么类型我有时候结合上下文件,还能找得到,但是有的时候最 ...

  3. 关于在VS 2013 Reshaper 中不能使用Alt+Enter 的解决

    新装Vs 2013 ,感觉还是不错,但是很恶心的是居然,Resharper 万能的快捷键不能用,让洒家真是恶心极了.   通过Google 在StackOverflow 上发现了解决方法,但好像看他的 ...

  4. JS 只创建一个元素

    //判断有没有这个元素<div id="div"> if(my$("div").firstElementChild){ console.log(&q ...

  5. JQ模拟触发事件

    jQuery 事件 - trigger() 方法 jQuery 事件参考手册 实例 触发 input 元素的 select 事件: $("button").click(functi ...

  6. JAVA基础——编程练习(三)

    熟悉String方法的使用之判断文件名是否合法 学习之余,写个小练习来巩固一下String的方法应用. 任务: 1.判断用户选择要输入的内容的类型 2.如果是java文件,输出“您输入的是java文件 ...

  7. DHCP协议及基本实现原理

    DHCP(Dynamic Host Configuration Protocol):动态主机配置协议. DHCP的优缺点 DHCP服务优点:网络管理员可以验证IP地址和其它配置参数,而不用去检查每个主 ...

  8. 解压与压缩(把dataset转为string、、 )

    /// <summary> /// 压缩 解压 /// </summary> public class ZipHelper { #region 压缩解缩 /// <sum ...

  9. vue从一个页面跳转到另一个页面并携带参数

    1.需求: 点击商场跳转到商业体列表 解决方案: 元页面: a标签中添加跳转函数 <a class="orderBtn1 sIRicon2" href="javas ...

  10. 【转】idea中applicationContext-trans.xml中的Cannot resolve bean 'dataSource'...的问题解决

    问题如下: (applicationContext-trans.xml中的部分截图) 先了解问题是怎么出现的: 此处的dataSource是在applicationContext-dao.xml中配置 ...