HttpMethod.java 765 B

123456789101112131415161718192021222324252627282930313233343536
  1. package com.ruoyi.common.enums;
  2. import java.util.HashMap;
  3. import java.util.Map;
  4. import org.springframework.lang.Nullable;
  5. /**
  6. * 请求方式
  7. *
  8. * @author ruoyi
  9. */
  10. public enum HttpMethod
  11. {
  12. GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE;
  13. private static final Map<String, HttpMethod> mappings = new HashMap<>(16);
  14. static
  15. {
  16. for (HttpMethod httpMethod : values())
  17. {
  18. mappings.put(httpMethod.name(), httpMethod);
  19. }
  20. }
  21. @Nullable
  22. public static HttpMethod resolve(@Nullable String method)
  23. {
  24. return (method != null ? mappings.get(method) : null);
  25. }
  26. public boolean matches(String method)
  27. {
  28. return (this == resolve(method));
  29. }
  30. }