Files
Arbitrate-Backend/ruoyi-common/src/main/java/com/ruoyi/common/enums/HttpMethod.java
T

33 lines
710 B
Java
Raw Normal View History

2023-09-06 18:13:01 +08:00
package com.ruoyi.common.enums;
import java.util.HashMap;
import java.util.Map;
2023-09-15 20:06:01 +08:00
2023-09-06 18:13:01 +08:00
import org.springframework.lang.Nullable;
/**
* 请求方式
*
* @author ruoyi
*/
2023-09-15 20:06:01 +08:00
public enum HttpMethod {
2023-09-06 18:13:01 +08:00
GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE;
private static final Map<String, HttpMethod> mappings = new HashMap<>(16);
2023-09-15 20:06:01 +08:00
static {
for (HttpMethod httpMethod : values()) {
2023-09-06 18:13:01 +08:00
mappings.put(httpMethod.name(), httpMethod);
}
}
@Nullable
2023-09-15 20:06:01 +08:00
public static HttpMethod resolve(@Nullable String method) {
2023-09-06 18:13:01 +08:00
return (method != null ? mappings.get(method) : null);
}
2023-09-15 20:06:01 +08:00
public boolean matches(String method) {
2023-09-06 18:13:01 +08:00
return (this == resolve(method));
}
}