0
I was using . delete but suddenly the method is not being recognized from the error in the console.
2017-04-12 09:51:34.022 WARN 5836 --- [nio-8080-exec-9] o.s.web.servlet.Pagenotfound: Request method 'POST' not supported
I’m sending it like this in html.
<form method="post">
<input type="hidden" name="_method" value="DELETE"/> </form>
and my controller is like this.
@PreAuthorize("hasAuthority('PERM_MANTENEDORA_EXCLUIR')")
@RequestMapping(value = "/excluir/{id}", method = RequestMethod.DELETE)*****************
public String excluirMantenedora(@PathVariable("id") Mantenedora mantenedora, RedirectAttributes attributes) {
if (mantenedora.getSituacao().getNome() == "ativo") {
try {
// condição para não deixar EXCLUIR quando tiver algum vínculo.
List<Instituicao> instituicoes = instituicaoRepository.findByMantenedoraId(mantenedora.getId());
if (instituicoes.size() <= 0) {
mantenedoraService.excluir(mantenedora.getId());
mensagem = mensagemSucesso(MensagemEnum.MENSAGEM_SUCESSO_EXCLUIR.getMensagem());
} else {
mensagem = mensagemErro(MensagemEnum.MENSAGEM_ERRO_VINCULO.getMensagem());
}
} catch (CustomException e) {
mensagem = mensagemErro(e.getMessage());
}
attributes.addFlashAttribute("mensagem", mensagem);
}
return "redirect:/mantenedora";
}
If I change DELETE to POST works but I want to know why it happened that the DELETE method is not recognized.
you need to change in your form the method of
<form method="post">for<form method="delete">. This occurs because your method expects a call via Delete,RequestMethod.DELETEbut within your form you are passing the call via post<form method="post">– brow-joe
vlw for the tip but I tried and now gave error in Get.
– Guilherme Oliveira
2017-04-12 10:34:40.317 WARN 3788 --- [nio-8080-exec-6] o.s.web.servlet.Pagenotfound: Request method 'GET' not supported
– Guilherme Oliveira
GET,POST,PUTandDELETE(there are others) are a part of the patternHTTP, but from what I’ve seen, formsHTMLare limited toGETandPOST. A solution would actually use asPOSTor still usePUTandDELETEwith requestsAJAX. To this end, consutle http://api.jquery.com/jQuery.ajax/– brow-joe