Spring post方法“缺少所需的请求正文" [英] Spring post method "Required request body is missing"

查看:604
本文介绍了Spring post方法“缺少所需的请求正文"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@PostMapping(path="/login")
public ResponseEntity<User> loginUser(@RequestBody Map<String, String> userData) throws Exception {
    return ResponseEntity.ok(userService.login(userData));
}

我在UserController中使用此方法进行登录.问题是当我尝试发出登录请求时,出现此错误:

I have this method for the login in the UserController. The problem is when i try to make the post request for the login i get this error:

{
"timestamp": "2018-10-24T16:47:04.691+0000",
"status": 400,
"error": "Bad Request",
"message": "Required request body is missing: public org.springframework.http.ResponseEntity<org.scd.model.User> org.scd.controller.UserController.loginUser(java.util.Map<java.lang.String, java.lang.String>) throws java.lang.Exception",
"path": "/users/login"
}



推荐答案

如果是POST请求,则必须将其作为JSON传递给您.

You have to pass that as JSON in your body, if it's a POST request.

这篇关于Spring post方法“缺少所需的请求正文"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆