一、@RequestParam

GET和POST请求传的参数会自动转换赋值到@RequestParam所注解的变量上

<form action="/requestParamDemo" method="get">
    用户名:<input type="text" name="username"><br>
    用户昵称:<input type="text" name="usernick"><br>
    <input type="submit" value="提交">
</form>
@RequestMapping(value = "/requestParamDemo", method = RequestMethod.GET)
public void requestParamDemo(@RequestParam(value = "username") String userName, @RequestParam(value = "usernick") String userNick) {
    System.out.println("username: " + userName);
    System.out.println("usernick: " + userNick);
}

二、@RequestBody

@RequestBody注解可以接收json格式的数据,并将其转换成对应的数据类型

// 通过ajax发送json数据
{
    "id":1,
    "username":"jack",
    "password":"1234"
}
@RequestMapping(value="/requestBodyDemo", method = RequestMethod.POST)
public void requestBodyDemo(@RequestBody User user){
    System.out.println("id: " + user.getId());
    System.out.println("name: " + user.getName());
    System.out.println("password: " + user.getPassword());
}

一个好奇的人