Quando eu executo o método gravar ocorre este erro de :
There was an unexpected error (type=Method Not Allowed, status=405). Request method 'POST' not supported
package br.com.melao.corretora.controller;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import br.com.melao.corretora.model.Segurado;
import br.com.melao.corretora.service.cadastro.SeguradoService;
@Controller
public class SeguradoController {
@Autowired
private SeguradoService seguradoService;
@RequestMapping("/sucesso")
public String sucesso() {
return "sucesso";
}
@RequestMapping(value="/segurado/cadastro-segurado" , method=RequestMethod.GET)
public ModelAndView cadastroSegurado(Segurado segurado) {
ModelAndView view = new ModelAndView("segurado/cadastro-segurado");
return view;
}
@RequestMapping(value="gravar" , method=RequestMethod.POST)
public ModelAndView gravar(@Valid Segurado segurado , BindingResult result) {
if(result.hasErrors()) {
return cadastroSegurado(segurado);
}
ModelAndView view = new ModelAndView("segurado/cadastro-segurado");
seguradoService.gravarUsuario(segurado);
return view;
}
@RequestMapping(value="/segurado/consulta-segurado", method= RequestMethod.GET)
public ModelAndView listarSegurado() {
ModelAndView seguradosView = new ModelAndView("/segurado/consulta-segurado");
seguradosView.addObject("listaSegurados",seguradoService.listar());
return seguradosView;
}
@RequestMapping(value="buscar" , method=RequestMethod.POST)
public ModelAndView buscar(Segurado segurado) {
ModelAndView seguradosView = new ModelAndView("segurado/cadastro-segurado");
seguradosView.addObject("listaSegurados",seguradoService.buscarPorNome(segurado));
return seguradosView;
}
}