問題描述:
-
在前后端傳遞參數(shù)時(shí),如果為JSON,后端使用@RequestBody對象類型接受數(shù)據(jù),會(huì)出現(xiàn) 500/400錯(cuò)誤。
-
也就是說,在前后端發(fā)送數(shù)據(jù)時(shí),出現(xiàn)JSON格式轉(zhuǎn)換錯(cuò)誤,從而訪問不到后臺(tái)接口。
-
不添加
@RequestBody
雖然可以成功訪問,但是無法獲取到對象數(shù)據(jù)文章來源:http://www.zghlxwxcb.cn/news/detail-511332.html -
警告內(nèi)容:
文章來源地址http://www.zghlxwxcb.cn/news/detail-511332.html
解決:
- 不要使用對象類型接受,統(tǒng)一使用 Map 接收數(shù)據(jù),就不會(huì)出現(xiàn)上述情況
-
@RequestBody Map<String, Object> data
取代@RequestBody ArrayList<String> data
// http://localhost:5679/student/select4
// {"list":["計(jì)算機(jī)系","英語系"]}
@PostMapping("/select4")
public List<Student> select4(@RequestBody Map<String, Object> list) {
return studentService.select4(list);
}
到了這里,關(guān)于JSON parse error: Cannot deserialize value of type `java.util.ArrayList<java.lang.String>`的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!