32

例如,HttpServletResponse将 HTTP 状态代码作为常量,例如

public static final int SC_OK = 200;
public static final int SC_CREATED = 201;
public static final int SC_BAD_REQUEST = 400;
public static final int SC_UNAUTHORIZED = 401;
public static final int SC_NOT_FOUND = 404;

是否在 Java EE API 中的任何地方为 HTTP 方法定义了任何此类常量GETPOST以便可以轻松引用它,而不是我自己创建一个?

4

1 回答 1

40

如果您使用的是 Spring,那么您有这个枚举org.springframework.web.bind.annotation.RequestMethod

public enum RequestMethod {
  GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE;
}

编辑:这是Java 6 中常量值的完整列表您可以看到其中一些在HttpMethod类中可用,但它包含的值比 RequestMethod 少。

public @interface HttpMethod {
  java.lang.String GET = "GET";
  java.lang.String POST = "POST";
  java.lang.String PUT = "PUT";
  java.lang.String DELETE = "DELETE";
  java.lang.String HEAD = "HEAD";
  java.lang.String OPTIONS = "OPTIONS";

  java.lang.String value();
}
于 2013-09-25T15:09:49.277 回答