您的位置:首页 > Web前端

前后端分离,传参数出现400错误

2016-11-21 18:15 609 查看
最近在做项目中的一个模块,一直卡在一块bug一直没有解决,项目一直报400错误,上网百度了一下400错误:

**HTTP 错误 400

400 请求出错

由于语法格式有误,服务器无法理解此请求。不作修改,客户程序就无法重复此请求。**

看这个解释,那应该是参数的问题,但是参数检查了一下怎么也没发现到底哪里少参数了

下面这个是前端发送的参数



下面是后端controller中的接受方法的部分

@RequestMapping(value = "save/all", method = RequestMethod.GET)
@ResponseBody
public JSONObject saveAll(@RequestParam(required = false, value = "id") Integer id,
@RequestParam(value = "dishId") Integer dishId,
@RequestParam(value = "mainCost") BigDecimal mainCost,
@RequestParam(value = "assistCost") BigDecimal assistCost,
@RequestParam(value = "deliciousCost") BigDecimal deliciousCost,
@RequestParam(value = "ingredientId") List<Integer> ingredientId,
@RequestParam(value = "itemType") List<Integer> itemType,
@RequestParam(value = "netCount") List<Integer> netCount,
@RequestParam(value = "otherCount") List<Integer> otherCount,
@RequestParam(value = "isAutoOut") List<Integer> isAutoOut,
ServletRequest request) throws SSException {


所有的参数都是一 一对应的,最后通过一个一个参数的在地址栏中的传递,找到了罪魁祸首:netCount,otherCount

这两个参数的类型出错了,传输过来的数值不能使用Integer来接收

把相应的接收改成

@RequestParam(value = "netCount") List<BigDecimal> netCount,
@RequestParam(value = "otherCount") List<BigDecimal> otherCount,


错误解决!!!以后要记着遇到问题不要盲目的去找问题,有时候可能一个一个的试参数会比漫无边际的寻找更有用!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  bug 前端
相关文章推荐