HTTP Status 415 HTTP Status 400 Post @requestbody Springmvc

1,先说一下自己的问题,用postman测试数据

<html>

<head>

<title>Apache Tomcat/7.0.59 - Error report</title>

<style>

<!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}-->

</style>

</head>

<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/7.0.59</h3>

</body>

</html>

报这个问题:

改成

就可以了

紧接着报

<html>
    <head>
        <title>Apache Tomcat/7.0.59 - Error report</title>
        <style>
            <!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}-->
        </style>
    </head>
    <body>
        <h1>HTTP Status 400 - </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 request sent by the client was syntactically incorrect.</u>
        </p>
        <HR size="1" noshade="noshade">
        <h3>Apache Tomcat/7.0.59</h3>
    </body>
</html>

主要原因就是端上和Springmvc的对接的参数不一致导致的。

端上的json数据是:

{
    "reqVoList": [
        {
            "cmmdtyName": "伊莱克斯冰箱EBM2500WA-R",
            "comingStockNum": "4",
            "createTime": "2019-01-18",
            "operator": "7017963441",
            "orderItemNo": "A100101462301",
            "orderNo": "A1001014623",
            "supplierCode": "0000000000"
        },
        {
            "cmmdtyName": "TCL冰箱BCD-211KD3闪白银",
            "comingStockNum": "1",
            "createTime": "2019-01-18",
            "operator": "7017963441",
            "orderItemNo": "A100101462302",
            "orderNo": "A1001014623",
            "supplierCode": "0000000000"
        }
    ]
}

后台接受的代码

@ResponseBody
@RequestMapping(value = "/saveBathInStock", method = RequestMethod.POST)
public ResponseVO<ConfirmWebPurchasInRspVO> saveBathInStock(@User LoginUser user, @RequestBody List<SaveInStockReqVo> reqList)

SaveInStockReqVo:

package com.suning.srcskf.vo.stock;

import java.io.Serializable;

public class SaveInStockReqVo implements Serializable {
    private static final long serialVersionUID = -2504062686085615430L;

    /**
     * 订单号
     */
    private String orderNo;

    /**
     * 订单行号
     */
    private String orderItemNo;

    private String storeStockCount;
    /**
     * 下单时间
     */

    private String purchaseTime;

    /**
     * 操作人
     */

    private String operateUser;
    /**
     * 门店编码
     */
    private String storeCode;

    /**
     *商编
     */
    private String cmmdtyCode;

    /**
     * 商品名称
     */
    private String cmmdtyName;

    private String barCode;

    private String updateUser;

    /**
     * 供应商:苏宁自营
     */
    private String supplier;

    /**
     * 供应商编码
     */
    private String supplierCode;

    /**
     * web端下单时间
     * @return
     */
    private String createTime;

    /**
     * web端操作人
     * @return
     */
    private String operator;
    /**
     * web入库数量
     * @return
     */
    private String comingStockNum;

    public String getComingStockNum() {
        return comingStockNum;
    }

    public void setComingStockNum(String comingStockNum) {
        this.comingStockNum = comingStockNum;
    }

    public String getOperator() {
        return operator;
    }

    public void setOperator(String operator) {
        this.operator = operator;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getSupplier() {
        return supplier;
    }

    public void setSupplier(String supplier) {
        this.supplier = supplier;
    }

    public String getSupplierCode() {
        return supplierCode;
    }

    public void setSupplierCode(String supplierCode) {
        this.supplierCode = supplierCode;
    }

    public String getPurchaseTime() {
        return purchaseTime;
    }

    public void setPurchaseTime(String purchaseTime) {
        this.purchaseTime = purchaseTime;
    }

    public String getOperateUser() {
        return operateUser;
    }

    public void setOperateUser(String operateUser) {
        this.operateUser = operateUser;
    }

    public String getOrderNo() {
        return orderNo;
    }

    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }

    public String getOrderItemNo() {
        return orderItemNo;
    }

    public void setOrderItemNo(String orderItemNo) {
        this.orderItemNo = orderItemNo;
    }

    public String getStoreStockCount() {
        return storeStockCount;
    }

    public String getCmmdtyName() {
        return cmmdtyName;
    }

    public void setCmmdtyName(String cmmdtyName) {
        this.cmmdtyName = cmmdtyName;
    }

    public void setStoreStockCount(String storeStockCount) {
        this.storeStockCount = storeStockCount;
    }

    public String getStoreCode() {
        return storeCode;
    }

    public void setStoreCode(String storeCode) {
        this.storeCode = storeCode;
    }

    public String getCmmdtyCode() {
        return cmmdtyCode;
    }

    public void setCmmdtyCode(String cmmdtyCode) {
        this.cmmdtyCode = cmmdtyCode;
    }

    public String getBarCode() {
        return barCode;
    }

    public void setBarCode(String barCode) {
        this.barCode = barCode;
    }

    public String getUpdateUser() {
        return updateUser;
    }

    public void setUpdateUser(String updateUser) {
        this.updateUser = updateUser;
    }
}

原因就是端上的json数据和vo不一致导致的

修改方法一:

修改json数据

[
    {
        "cmmdtyName": "伊莱克斯冰箱EBM2500WA-R",
        "comingStockNum": "4",
        "createTime": "2019-01-18",
        "operator": "7017963441",
        "orderItemNo": "A100101462301",
        "orderNo": "A1001014623",
        "supplierCode": "0000000000"
    },
    {
        "cmmdtyName": "TCL冰箱BCD-211KD3闪白银",
        "comingStockNum": "1",
        "createTime": "2019-01-18",
        "operator": "7017963441",
        "orderItemNo": "A100101462302",
        "orderNo": "A1001014623",
        "supplierCode": "0000000000"
    }
]

方式二,修改java代码

在创建一个新类:

比如A

package com.suning.srcskf.vo.stock;

import java.util.List;

public class A {
    List<SaveInStockReqVo> reqVoList;

    public List<SaveInStockReqVo> getReqVoList() {
        return reqVoList;
    }

    public void setReqVoList(List<SaveInStockReqVo> reqVoList) {
        this.reqVoList = reqVoList;
    }

}

控制层改成这样

public ResponseVO<ConfirmWebPurchasInRspVO> saveBathInStock(@User LoginUser user, @RequestBody A a)

原文地址:https://www.cnblogs.com/qingruihappy/p/10340241.html

时间: 2024-10-06 20:10:45

HTTP Status 415 HTTP Status 400 Post @requestbody Springmvc的相关文章

HTTP Status 415 – Unsupported Media Type(使用@RequestBody后postman调接口报错)

1.问题描述:使用springMVC框架后,添加数据接口中,入参对象没使用@RequestBody注解,造成postman发起post请求, from-data可以调通接口,但是raw调不通接口,然后我用了SpringMVC @ResponseBody 注解,调接口显示415错误处理. 处理: springmvc添加配置.注解: 1 <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHan

在SpringMVC中使用@RequestBody注解处理json时,报出HTTP Status 415的解决方案

Spring的@RequestBody非常牛x,可以将提交的json直接转换成POJO对象. 正好今天有这样的需求,使用一下,结果一直报415,十分头疼. HTTP 415 错误 – 不支持的媒体类型(Unsupported media type) 我的angularJs是这样写的 $http({method: "POST", url: url; headers: {'Content-type': 'application/json;charset=UTF-8'}, data: sco

在SpringMVC中使用@RequestBody和@ResponseBody注解处理json时,报出HTTP Status 415的解决方案

我在使用SpringMVC的@RequestBody和@ResponseBody注解处理JSON数据的时候,总是出现415的错误,说是不支持所提交数据格式,我在页面中使用了JQuery的AJAX来发出JSON数据给服务器: $.ajax({ type:'post', url:'${pageContext.request.contextPath }/requestJSON.action', contentType :'application/json;charset=utf-8', //数据是JS

JMeter 脚本请求错误 HTTP Status 415 的解决

然后在http请求上点击右键,添加配置元件-http信息头管理器,在信息头管理器上,添加一个参数,名称:Content-Type,值:application/json.然后在http请求上,content encoding处填上utf-8.把你要传的json串拷贝到body data里.只要你的脚本没问题,应该就不会报415了

SpringMVC @RequestBody接收JSON报HTTP 415问题的解决方法

现在做的一个项目是做app服务端的,需要从app接收json的请求数据,服务端框架用的是SpringMVC,所以自然而然的想到直接用@RequestBody来接收json数据, 格式如下: public ResponseProtocolMap login(@RequestBody JSONObject requestJson,HttpServletRequest request) { ResponseProtocolMap responseProtocolMap = null; //中间内容省略

Http Status

http_status_bad_request (400) the request could not be processed by the server due to invalid syntax. 因为语法不能被服务器处理 HTTP Status 400 - type Status report message description The request sent by the client was syntactically incorrect. Apache Tomcat/8.0.

SpringMVC---400错误The request sent by the client was syntactically incorrect ()

在SpringMVC中使用@RequestBody和@ModelAttribute注解时遇到了很多问题,现记录下来. @ModelAttribute这个注解主要是将客户端请求的参数绑定参数到一个对象上,不用将很多参数@RequestParam或是@PathVariable. 但是在使用过程中遇到了问题, 第一次Html端请求代码如下,请求方式1 // 简单键值对 var data = { productTypeIds : vproducttypeid, channelTypeId : vchan

HTTP状态码(HTTP Status Code)

HTTP状态码(HTTP Status Code)是用以表示网页服务器HTTP响应状态的3位数字代码.它由 RFC 2616 规范定义的,并得到RFC 2518.RFC 2817.RFC 2295.RFC 2774.RFC 4918等规范扩展. HTTP: Status 1xx (临时响应) ->表示临时响应并需要请求者继续执行操作的状态代码. 详细代码及说明: HTTP: Status 100 (继续) -> 请求者应当继续提出请求. 服务器返回此代码表示已收到请求的第一部分,正在等待其余部

常见http status code

常见http status code 常见的状态码: HTTP: Status200– 服务器成功返回网页 HTTP: Status404– 请求的网页不存在 HTTP: Status503– 服务不可用 ———————————————————————————————— HTTP: Status 1xx(临时响应) ->表示临时响应并需要请求者继续执行操作的状态代码. 详细代码及说明: HTTP: Status 100(继续) -> 请求者应当继续提出请求. 服务器返回此代码表示已收到请求的第