ModelAndView返回方法对象

时间:2018-12-03 18:17:53

标签: java spring spring-mvc modelandview

我有此代码:

@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错误

1 个答案:

答案 0 :(得分:0)

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

SELECT t1.id FROM myplugin.db.t1, myplugin2.db.t2 WHERE t1.id = t2.id AND t2.id = 12345 GROUP BY t1.id ORDER BY t1.id;