33 lines
710 B
Java
Raw Normal View History

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