场景是在希望用ajax发post请求,传递一个json对象,在controller中直接使用java对象接收时遇到的,具体错误信息如下:

{
"timestamp": 1500272249207,
"status": 415,
"error": "Unsupported Media Type",
"exception": "org.springframework.web.HttpMediaTypeNotSupportedException",
"message": "Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported",
"path": "/addSuggestions"
}

原因如错误信息里所说:Content type不支持。将Content type改为:application/json可以解决问题。

本人使用postman模拟的http请求,简单如下:

对应controller处理:

package cn.migu.battle.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import cn.migu.battle.constant.InterfaceConstant;
import cn.migu.battle.model.UserSuggestionModel;
import cn.migu.battle.service.UserSuggestionService;
import cn.migu.battle.utils.JsonResponseForList; /**
*
* @author Administrator
*
*/
@RestController
public class UserSuggestionController { @Autowired
private UserSuggestionService service; @RequestMapping(value = "/addSuggestions",method = {RequestMethod.POST})
public JsonResponseForList addSuggestion(@RequestBody(required = false) UserSuggestionModel model){
if(!service.addSuggestions(model)){
return new JsonResponseForList(InterfaceConstant.STATUS_FAILURE,InterfaceConstant.MESSAGE_FAILURE,null);
}
return new JsonResponseForList(InterfaceConstant.STATUS_SUCCESS,InterfaceConstant.MESSAGE_SUCCESS,null);
}
}

具体解释不再赘述,参考链接:

http://blog.csdn.net/LostSh/article/details/68923874

http://blog.csdn.net/ccc20134/article/details/45094679

问题.springmvc错误.415:Unsupported Media Type的更多相关文章

  1. springmvc4.3.7中使用RequestBody,传入json参数时,得到错误415 Unsupported Media Type

    在新建一个maven的项目的时候,当时并非springboot项目,是通过xml来配置的项目.在项目中DispatcherServlet的配置文件中配置了annotation-driven的, < ...

  2. SpringMVC 中HttpMessageConverter简介和Http请求415 Unsupported Media Type的问题

    一.概述: 本文介绍且记录如何解决在SpringMVC 中遇到415 Unsupported Media Type 的问题,并且顺便介绍Spring MVC的HTTP请求信息转换器HttpMessag ...

  3. springMVC中使用 RequestBody 及 Ajax POST请求 415 (Unsupported Media Type)

    使用POST请求的时候一直报错: Ajax 未设置 contentType 时会报 415 . 后台 RequestBody  承接前台参数,故对参数data的要求为“必传”“JSON”,否则会报40 ...

  4. Darwin Streaming Server服务器mp4文件点播返回”415 Unsupported Media Type“错误

    Darwin Streaming Server中mp4文件点播失败,通过抓包发现服务器返回”415 Unsupported Media Type“错误,如下: RTSP/ Unsupported Me ...

  5. [.NET Core]ASP.NET Core中如何解决接收表单时的不支持的媒体类型(HTTP 415 Unsupported Media Type)错误呢?

    [.NET Core]ASP.NET Core中如何解决接收表单时的不支持的媒体类型(HTTP 415 Unsupported Media Type)错误呢? 在ASP.NET Core应用程序中,接 ...

  6. angularjs - 415 (Unsupported Media Type)

    angularJs+springMVC angular表单提交一个user实体时,报 angularjs - 415 (Unsupported Media Type)错误!! 原因是$http({ u ...

  7. request 报错The remote server returned an error: (415) Unsupported Media Type.

    开发时遇到个问题,程序访问数据库数据,给服务器发送请求时,老是报错,返回的错误页面是: HTTP Status 415 - Unsupported Media Type type Status rep ...

  8. System.Net.WebException : The remote server returned an error: (415) UNSUPPORTED MEDIA TYPE

    I am having problems with a bit of code that accesses a restful web service. Running this code, it e ...

  9. RestTemplate远程调用POST请求:HTTP 415 Unsupported Media Type

    这是本项目的接口 称为client @POST @Path("/{urlcode}") @Consumes(MediaTypes.JSON_UTF_8) @Produces(Med ...

随机推荐

  1. 温故而知新,重温 Java 7 的那些“新”特性

    2009 年 4 月 20 日,Java 的亲生父亲 Sun 被养父 Oracle 以 74 亿美元收购,这在当时可是一件天大的事.有不少同学都担心 Java 的前途,我当时傻不啦叽地也很担心:自己刚 ...

  2. VS Code 安装 LeetCode 插件

    练习算法绕不开的一个网站就是力扣,很多小伙伴为了拿到大厂 offer,刷题都刷到吐了. 然而如果直接在 LeetCode 上写代码,那是很痛苦的一件事,那就相当于用 txt 写代码一样,没有 IDE ...

  3. jQuery写toTop(回到顶部)效果

    在通常的网站开发中,页面有时候会很长,尤其是一些电商网站,为了提高用户的体验效果,我们通常会增加一个回到顶部的按钮,这个按钮我们同城会使用fixed定位,将其定位在当前可视区域某一固定位置.这个效果用 ...

  4. 【Android】SDK Manager 设置代理

    这里是 Mac 系统下,Windows 环境类似.打开 Android SDK Manager, Proxy Settings 设置如下所示: PS: 注意勾选 "Force https:/ ...

  5. scroll-苹果滑动卡顿

    2018年08月02日,程序小bug. 在移动端html中经常出现横向/纵向滚动的效果,但是在iPhone中滚动速度很慢,感觉不流畅,有种卡卡的感觉,但是在安卓设备上没有这种感觉; 一行代码搞定: - ...

  6. 又拍云叶靖:OpenResty 在又拍云存储中的应用

    2019 年 7 月 6 日,OpenResty 社区联合又拍云,举办 OpenResty × Open Talk 全国巡回沙龙·上海站,又拍云平台开发部负责人叶靖在活动上做了<OpenRest ...

  7. Vue系列:为不同页面设置body背景颜色

    由于SPA页面的特性,传统的设置 body 背景色的方法并不通用. 解决方案:利用组件内的路由实现 代码参考如下

  8. 网络编程网络协议篇(osi七层协议)

    一 互联网的本质 咱们先不说互联网是如何通信的(发送数据,文件等),先用一个经典的例子,给大家说明什么是互联网通信. 现在追溯到八九十年代,当时电话刚刚兴起,还没有手机的概念,只是有线电话,那么此时你 ...

  9. -bash: redis: command not found

    在linux中安装redis,先是拉过去安装,然后通过命令:make   进行编译  编译完成以后通过命令 make install 完成安装:结果在进行启动linux的时候执行           ...

  10. Oracle 12cR1 RAC集群安装(一)--环境准备

    基本环境 操作系统版本 RedHat6.7 数据库版本 12.1.0.2 数据库名称 testdb 数据库实例 testdb1.testdb2 (一)安装服务器硬件要求 配置项目 参数要求 网卡 每台 ...