查找HTTP动词,该动词应为GET,POST,PUT,DELETE,OPTIONS或HEAD。
import java.lang.annotation.Annotation; import java.lang.reflect.Method; import javax.ws.rs.DELETE; /* 来自 *N o w J a v a . c o m - 时代Java*/ import javax.ws.rs.GET; import javax.ws.rs.HEAD; import javax.ws.rs.HttpMethod; import javax.ws.rs.OPTIONS; import javax.ws.rs.POST; import javax.ws.rs.PUT; public class Main{ /** * Look for the HTTP verb which should be {@link GET}, {@link POST}, {@link PUT}, {@link DELETE}, {@link OPTIONS} or {@link HEAD}. * * @param method - that potentially has an annotation. * @return {@link HttpMethod} or null. */ public static HttpMethod resolveHttpType(Method method) { for (Annotation annotation : method.getDeclaredAnnotations()) { final HttpMethod httpMethod = annotation.annotationType() .getAnnotation(HttpMethod.class); /** N o w