登录

java - Springmvc中@RequestBody和@RequestParam能够同时使用吗

 @RequestMapping(value = "", method = RequestMethod.POST)
    public Result get(@RequestBody User user,
                      @RequestParam("username") String hehe) throws Exception {

}

如何能够接受user对象的同时,同时接受username?

假设User对象为

public class User  {

    private String id;

    private String username;

    private String email;

    private String phone;
}
# Java
PHP中文网PHP中文网2188 天前430 次浏览

全部回复(2) 我要回复

  • PHP中文网

    PHP中文网2017-04-17 17:56:20

    post http://url?username=123
    {
        id: "",
        username: "",
        email: "",
        phone: ""
    }

    回复
    0
  • PHP中文网

    PHP中文网2017-04-17 17:56:20

    可以的
    如:
    post 一个json数据到
    http://www.google.com?code=1024

    RequestParams 就是 code=1024
    RequestBody 就是你的json数据(题外话:注意content-type)

    回复
    0
  • 取消回复发送