赞
踩
Axios发送数组请求后端接口报错400
SpringBoot警告内容:Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type com.xx.xx.xx.User
from Array value (token JsonToken.START_ARRAY
); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type com.xx.xx.xx.User
from Array value (token JsonToken.START_ARRAY
) at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 1, column: 1]]
后端代码:
@DeleteMapping
@PreAuthorize("hasAuthority('ROLE_ADMIN')")
public ResponseEntity<Object> removeUser(@RequestBody List<Integer> ids) {
return new ResponseEntity<>(userService.removeUser(ids), HttpStatus.OK);
}
使用postman请求后端没有警告,使用axios请求报错。
这是一个Jackson库的异常,表示在反序列化JSON时发生了输入不匹配的错误。可能是JSON格式不正确或与Java对象不匹配。需要检査JSON格式和Java对象的匹配性。
前端:axios请求方法更换为method: ‘delete’
export function XXXXX(url, data) {
return request({
url: url,
method: 'delete',
data: data
})
}
后端代码:
@DeleteMapping
@PreAuthorize("hasAuthority('ROLE_ADMIN')")
public ResponseEntity<Object> removeUser(@RequestBody List<Integer> ids) {
return new ResponseEntity<>(userService.removeUser(ids), HttpStatus.OK);
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。