Vue向后端发生请求时出现xhr.js?ec6c:177 GET http://localhost:8989/vue/user/findOne?id=9 net::ERR_CONNECTION_REF

xhr.js?ec6c:177 GET http://localhost:8989/vue/user/findOne?id=9 net::ERR_CONNECTION_REFUSED
Uncaught (in promise) Error: Network Error

原因
前端通过post请求向后端发送请求传递参数时,后端以springboot为例接收参数需要添加注解支持
解决方法
在参数中添加@RequestBody

/**
   * 修改用户信息
   */
  @PostMapping("update")
  public Map<String,Object> update(@RequestBody  User user){
    
    
    HashMap<String , Object> map = new HashMap<>();

    try {
    
    
      userService.update(user);
      map.put("success", true);
      map.put("msg", "修改用户成功!");
    } catch (Exception e) {
    
    
      e.printStackTrace();
      map.put("success", false);
      map.put("msg", "修改用户失败:" + e.getMessage());
    }
    return map;
  }

猜你喜欢

转载自blog.csdn.net/weixin_46195957/article/details/110510343