当前位置:   article > 正文

JSON parse error: Cannot deserialize value of type `long` from Object value (token `JsonToken.START__cannot deserialize value of type `int` from object

cannot deserialize value of type `int` from object value (token `jsontoken.s

前端发送的json格式对象后端不能直接用参数接收,要封装一个接收类

  1. export async function deleteUser(body: API.deleteid, options?: { [key: string]: any }) {
  2. return request<API.BaseResponse<boolean>>('/api/user/delete', {
  3. method: 'POST',
  4. headers: {
  5. 'Content-Type': 'application/json',
  6. },
  7. data: body,
  8. ...options,
  9. });
  10. }

后端接收参数报错

  1. @PostMapping("/delete")
  2. BaseResponse<Boolean> deleteUser(@RequestBody long id, HttpServletRequest request){
  3. boolean b = userService.deleteUser(userDeleteDTO.getId(), request);
  4. return ResultUtils.success(b);
  5. }

改为

  1. @PostMapping("/delete")
  2. BaseResponse<Boolean> deleteUser(@RequestBody UserDeleteDTO userDeleteDTO, HttpServletRequest request){
  3. boolean b = userService.deleteUser(userDeleteDTO.getId(), request);
  4. return ResultUtils.success(b);
  5. }
  1. @Data
  2. public class UserDeleteDTO {
  3. private long id;
  4. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/木道寻08/article/detail/896763
推荐阅读
相关标签
  

闽ICP备14008679号