http 傳引數出現400錯誤
阿新 • • 發佈:2019-02-20
最近在做專案中的一個模組,一直卡在一塊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 {
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
所有的引數都是一 一對應的,最後通過一個一個引數的在位址列中的傳遞,找到了罪魁禍首:netCount,otherCount
這兩個引數的型別出錯了,傳輸過來的數值不能使用Integer來接收
把相應的接收改成
@RequestParam(value = "netCount") List<BigDecimal> netCount,
@RequestParam(value = "otherCount") List<BigDecimal> otherCount,
- 1
- 2
- 3
錯誤解決!!!以後要記著遇到問題不要盲目的去找問題,有時候可能一個一個的試引數會比漫無邊際的尋找更有用!!
原文地址:https://blog.csdn.net/zgrgfr/article/details/53262110