Java 中是否有用于指代 HTTP 请求方法的标准常量?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2687441/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a standard constant in Java used to refer to HTTP request methods?
提问by user167019
Possible Duplicate:
Where are the request method constants in the Servlet API?
可能的重复:
Servlet API 中的请求方法常量在哪里?
I'm looking for a Java string constant to refer to HTTP request methods (GET, POST, PUT, etc.). I expected HttpServletor HttpServletRequest to have constants for these methods, but that doesn't seem to be the case.
我正在寻找一个 Java 字符串常量来引用 HTTP 请求方法(GET、POST、PUT 等)。我希望HttpServlet或 HttpServletRequest 具有这些方法的常量,但情况似乎并非如此。
回答by Thilo
回答by Chris J
In Java Spring, you can use the RequestMapping annotation to isolate different types of request methods. It is in section 13.11.3 of the following link: http://static.springsource.org/spring/docs/2.5.x/reference/mvc.html#mvc-annotation
在 Java Spring 中,您可以使用 RequestMapping 注解来隔离不同类型的请求方法。它位于以下链接的第 13.11.3 节中:http://static.springsource.org/spring/docs/2.5.x/reference/mvc.html#mvc-annotation
Essentially you can use these annotations to get the HTTP request method type:
本质上,您可以使用这些注释来获取 HTTP 请求方法类型:
@RequestMapping(method = RequestMethod.GET)
@RequestMapping(method = RequestMethod.POST)
@RequestMapping(method = RequestMethod.PUT)
All the request types are in an enum in the RequestMethod object: http://apollo89.com/java/spring-framework-2.5.3/api/org/springframework/web/bind/annotation/RequestMethod.html
所有请求类型都在 RequestMethod 对象的枚举中:http: //apollo89.com/java/spring-framework-2.5.3/api/org/springframework/web/bind/annotation/RequestMethod.html

