【问题标题】:spring-boot: can i fix next error in spring-boot 2?spring-boot:我可以修复 spring-boot 2 中的下一个错误吗?
【发布时间】:2019-05-01 19:28:55
【问题描述】:

我有这个代码:

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping(method = RequestMethod.GET,value = "/login")
    public ResponseEntity<User> getUser(@RequestBody User user) {

        if (userService.findByEmailAndPassword(user.getUsername(), user.getPassword()) !=null) {
            return new ResponseEntity<User>(user, HttpStatus.OK);
        }
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);

   }
}

当我尝试在 swegger 中使用 ths 方法时,会显示下一个错误: 我不知道如何解决这个错误,我需要帮助! 此方法用于登录android-app,但尚未准备好使用

{
  "timestamp": 1543509200623,
  "status": 400,
  "error": "Bad Request",
  "exception": "org.springframework.http.converter.HttpMessageNotReadableException",
  "message": "Required request body is missing: public org.springframework.http.ResponseEntity<edu.utcluj.track.user.User> edu.utcluj.track.user.UserController.getUser(edu.utcluj.track.user.User)",
  "path": "/user/login"
}

【问题讨论】:

    标签: java mysql database spring-boot get


    【解决方案1】:

    在我看来,您需要在 POST 请求中将 User 对象作为请求正文发送。它没有找到请求正文,因为您使用的是未发送请求正文的 GET 请求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-15
      • 1970-01-01
      • 2017-10-09
      • 2023-03-04
      • 1970-01-01
      • 2023-02-22
      • 2023-01-28
      • 2020-08-25
      相关资源
      最近更新 更多