|
|
@@ -1,8 +1,17 @@
|
|
|
package com.roma.romaapi.utils;
|
|
|
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
+import com.fasterxml.jackson.databind.JavaType;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import jakarta.servlet.http.HttpServletRequest;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import static com.roma.romaapi.utils.JWTUtil.SIGN;
|
|
|
|
|
|
@@ -30,4 +39,33 @@ public class CommonUtil {
|
|
|
String redisTokenKey = SIGN + token;
|
|
|
return stringRedisTemplate.delete(redisTokenKey);
|
|
|
}
|
|
|
+
|
|
|
+ public Map analysisRequestParams(HttpServletRequest request, @RequestBody String data) {
|
|
|
+ Map<String, String[]> maps = request.getParameterMap();
|
|
|
+ String requestContentType = request.getContentType(); // 请求类型
|
|
|
+ Map ret = new HashMap<>();
|
|
|
+ if (requestContentType.equals("application/x-www-form-urlencoded")) {
|
|
|
+ // 组装要绑定的参数数据
|
|
|
+ for (Map.Entry<String, String[]> entry : maps.entrySet()) {
|
|
|
+ String paramsKey = entry.getKey();
|
|
|
+ String paramsValue = entry.getValue()[0];
|
|
|
+ ret.put(paramsKey, paramsValue);
|
|
|
+ }
|
|
|
+ } else if (requestContentType.equals("application/json")) {
|
|
|
+ try {
|
|
|
+ ObjectMapper jacksonMapper = new ObjectMapper();
|
|
|
+ Map<String, String> jsonParams = jacksonMapper.readValue(data, new TypeReference<Map<String, String>>() {});
|
|
|
+ // 组装要绑定的参数数据
|
|
|
+ for (Map.Entry<String, String> entry : jsonParams.entrySet()) {
|
|
|
+ String paramsKey = entry.getKey();
|
|
|
+ String paramsValue = entry.getValue();
|
|
|
+ ret.put(paramsKey, paramsValue);
|
|
|
+ }
|
|
|
+ }catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
}
|