@RequestBody
http://localhost:8080/user/login
{
"username":"jack",
"passward":null,
"createTime":null
}
@RequestBody 主要处理json
@PostMapping("/user/login")
@WebLog(description = "请求了用户登录接口")
public User userLogin(@RequestBody User user) {
logger.info("user login ...");
return user;
}
@RequestParm
http://localhost:8080/user/login?token=123
{
"username":"jack",
"passward":null,
"createTime":null
}
@RequestParm主要处理参数,required = false就是用户的请求的参数并没有输入不会报错,如果是true就会报错
*/
@PostMapping("/user/login")
@WebLog(description = "请求了用户登录接口")
/*
public User userLogin(@RequestBody User user) {
logger.info("user login ...");
return user;
}
*/
public User userLogin(@RequestBody User user,@RequestParam(value = "token",required = false) String token) {
logger.info("user login ...");
logger.info("user login token {}",token);
return user;
}
当为required =true的时候,http://localhost:8080/user/login输入的返回是
{
"timestamp": "2019-09-06T09:08:10.747+0000",
"status": 400,
"error": "Bad Request",
"message": "Required String parameter 'token' is not present",
"path": "/user/login"
}