警告:org.springframework.web.servlet.PageNotFound – 不支持请求方法’GET’
启动服务器时出现此exception: HTTP Status 405 - Request method 'GET' not supported
我的控制器是:
@Controller public class HomeController { private static final Logger logger = LoggerFactory.getLogger(HomeController.class); @RequestMapping(value = "/", method = RequestMethod.POST) public String home(Locale locale, Model model) { logger.info("Welcome home! The client locale is {}.", locale); return "login"; } }
我真的不知道是什么问题,因为我是一个非常新的spring,甚至无法弄清楚问题是什么。
有人可以指导我解决这个问题
试试这个
更改
@RequestMapping(value = "/", method = RequestMethod.POST)
至
@RequestMapping(value = "/login", method = RequestMethod.GET)
(在你上一篇文章中,我注意到你有login-page = login)
RequestMapping是错误的。
@RequestMapping(value =“/”,method = RequestMethod.POST
)
它只需要POST请求并返回405 StatusCode任何请求而不是POST。
所以,它应该是
@RequestMapping(value =“/”,method = RequestMethod.GET
)
更改
@RequestMapping(value = "/", method = RequestMethod.POST)
至
@RequestMapping(value = "/login", method = RequestMethod.GET)