DEMO的时候,在执行update操作后出现了 HTTP Status 405 - Request method 'PUT' not supported的错误。这类错括 method(PUT,DELETE,POST)not supported,原因很有可能就是后台中的uri(即handler类中)与前端 的uri不一致导致的。那么怎样找到这种错误并且修改呢?

SpringMVC中出现”HTTP Status 405 - Request method



可以看到,Request URL:​http://localhost:8080/springmvc_2/addNewEmp。即提交后跳入到addNewEmp页面中。而在后端代码中;​


<span style="font-size:18px;">@RequestMapping(value="/edit",method=RequestMethod.PUT)
public String update(Employee employee){
employeeDao.save(employee);
return "redirect:/empInfo_show";
}</span>


即提交后容器找到method为PUT,同时value="addNewEmp"的url,而我这里写的是"/edit”,路径不对当然就找不到页面了,所以报错了。所以改为:

@RequestMapping(value="/addNewEmp",method=RequestMethod.PUT)即可。


总而言之,解决这类的办法就是看@RequestMapping(value="/url1",method=RequestMethod.method*)中的url与前端页面中地址是否一致的问题。根本原因还是对SpringMVC机制的原理理解不够透彻,多加练习吧。