首页 > 解决方案 > 转换 get 到 post http 方法

问题描述

我正在做简单的 api 任务,一切都很好。但我不会转换一些东西,我不知道怎么做!

@RequestMapping("/user/{id}")
public ResponseEntity<Users> getUserById(@PathVariable Integer id) {
    return ResponseEntity.ok(userService.getUserById(id));
}

我想将此get方法转换为post方法,因此将id发送到body中然后获取结果。我怎样才能做到这一点?我可以这样登录吗?检查电子邮件和密码,如果它是真的然后重定向到另一个页面,或者有办法以最好的方式做到这一点?

标签: javaspring-boot

解决方案


使用 value 和 method 属性将其转换为 post。

@RequestMapping("/user/{id}", method = RequestMethod.POST)
public ResponseEntity<Users> getUserById(@Param Integer id) {
    return ResponseEntity.ok(userService.getUserById(id));
}

推荐阅读