小编Bar*_*tek的帖子

Spring Boot - 不支持请求方法'POST'

PageNotFound: Request method 'POST' not supported我的Spring Boot应用程序中出现异常.

这是我的控制器:

@RestController
public class LoginController {

UserWrapper userWrapper = new UserWrapper();

@RequestMapping(value = "/api/login", method = RequestMethod.POST, headers = "Content-type: application/*")
public @ResponseBody ResponseEntity getCredentials(@RequestBody UserDTO userDTO) {

    User user = userWrapper.wrapUser(userDTO);
    if (userDTO.getPassword().equals(user.getPassword())) {
        return new ResponseEntity(HttpStatus.OK);
    } else {
        return new ResponseEntity(HttpStatus.BAD_REQUEST);
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我发送邮件请求,localhost:8080/api/login但它不起作用.你有什么想法吗?

编辑:

UserDTO:

public class UserDTO implements Serializable {

private String email;
private String password;
//getters and setters
Run Code Online (Sandbox Code Playgroud)

和json我发送:

{
   "email":"email@email.com",
   "password":"password"
}
Run Code Online (Sandbox Code Playgroud)

java spring spring-boot

4
推荐指数
2
解决办法
2万
查看次数

标签 统计

java ×1

spring ×1

spring-boot ×1