method屬性
method屬性用來訓示方法僅僅處理哪些http請求方式,可支援一個或多個請求方式。
@RequestMapping("/hello",method=RequestMethod.POST)表示隻支援POST請求方式。
@RequestMapping("/hello",method={RequestMethod.POST,RequestMethod.GET})表示隻支援POST和GET請求方式。
如果沒有指定method屬性,則請求處理方法可以處理任意請求處理方式。
注意:
由于form表單隻支援GET和POST請求,而不支援DELETE和PUT等請求方式,Spring提供了一個過濾器HiddenHttpMethodFilter,可以将DELETE和PUT請求轉換為标準的HTTP請求,即能将POST請求轉換為DELETE或者PUT請求。
在web.xml檔案中配置過濾器HiddenHttpMethodFilter,如下所示:
<!-- 配置HiddenHttpMethodFilter,可将POST請求轉換為DELETE或者PUT -->
<filter>
<filter-name>HiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HiddenHttpMethodFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>