HttpMethod.java 710 B

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