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