0

我有这个代码:

@Controller
public class createUserController {

    @RequestMapping(value = "/user/registerUser", method = RequestMethod.GET, produces = "application/json")
    public ModelAndView createFleet(HttpServletRequest request, HttpServletResponse response, User user) {

        ModelAndView model = new ModelAndView();
        model.setView(new MappingJackson2JsonView());


        model.addObject("userCreated", new UserCreateResponse(user.getId(), user.getAccessCode()));

        return model;

    }
}

回应:

   {
  "user": {
    "id": null,
    "userName": "3",
    "password": "eccbc87e4b5ce2fe28308fd9f2a7baf3",
    "email": "3",
    "accessCode": "3"
  },
  "userCreated": {
    "id": null,
    "accessCode": "3"
  }
}

我不希望主要用户包含在响应中。我只是想要减少的细节,所以我不会发回原始请求。我试过 .clear() 但这给出了 404 错误

4

1 回答 1

0

您可以按如下方式更改控制器。当您尝试注册用户时,您应该使用 POST 而不是 GET。

@RestController
public class createUserController {

    @PostMapping("/user/registerUser")
    public UserCreateResponse createFleet(HttpServletRequest request, HttpServletResponse response, User user) {

      return new UserCreateResponse(user.getId(), user.getAccessCode());        

    }
}
于 2018-12-04T07:44:41.947 回答