SpringMVC構造restful URL解決請求綁值問題,springmvcrestful
Restful軟體架構風格--請參考百度簡述
轉載請註明出處點擊開啟連結
我們都知道為了能夠實現restful,必須要在web.xml中配置
<filter> <filter-name>HiddenHttpMethodFilter</filter-name> <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class> </filter> <filter-mapping> <filter-name>HiddenHttpMethodFilter</filter-name> <servlet-name>spring</servlet-name> </filter-mapping>
配置過後確實是可以接受PUT,DELETE等請求了,但是我想使用Spring中參數自動綁定就不行了,頁面傳過來的值都為null,經過我反覆測試和搜尋,
在Spring3.0中擷取put表單的參數-值還有另一種方法! => 使用HttpPutFormContentFilter過濾器。
HttpPutFormContentFilter過濾器的作為就是擷取put表單的值,並將之傳遞到Controller中標註了method為RequestMethod.put的方法中。
總算是解決這一問題了,只需要把上面配置改為:
<filter> <filter-name>HttpMethodFilter</filter-name> <filter-class>org.springframework.web.filter.HttpPutFormContentFilter</filter-class> </filter> <filter-mapping> <filter-name>HttpMethodFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
這樣就可以了