我的Spring Boot应用程序中不支持异常PageNotFound:Request方法’POST’.
这是我的控制器:
@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);
}
}
}
我在localhost发送邮件请求:8080 / api / login但它不起作用.你有什么想法吗?
编辑:
UserDTO:
public class UserDTO implements Serializable {
private String email;
private String password;
//getters and setters
和json我发送:
{
"email":"email@email.com",
"password":"password"
}
解决方法:
我通过禁用CSRF解决了这个问题.
@Configuration
class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
}
}
标签:java,spring,spring-boot-2
来源: https://codeday.me/bug/20190716/1476506.html