RuoYi лет назад: 4
Родитель
Сommit
7a35c474d6

+ 1 - 1
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/CacheConstants.java

@@ -10,7 +10,7 @@ public class CacheConstants
10
     /**
10
     /**
11
      * 令牌自定义标识
11
      * 令牌自定义标识
12
      */
12
      */
13
-    public static final String HEADER = "Authorization";
13
+    public static final String TOKEN_AUTHENTICATION = "Authorization";
14
 
14
 
15
     /**
15
     /**
16
      * 令牌前缀
16
      * 令牌前缀

+ 9 - 1
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/SecurityUtils.java

@@ -42,7 +42,15 @@ public class SecurityUtils
42
      */
42
      */
43
     public static String getToken(HttpServletRequest request)
43
     public static String getToken(HttpServletRequest request)
44
     {
44
     {
45
-        String token = ServletUtils.getRequest().getHeader(CacheConstants.HEADER);
45
+        String token = request.getHeader(CacheConstants.TOKEN_AUTHENTICATION);
46
+        return replaceTokenPrefix(token);
47
+    }
48
+
49
+    /**
50
+     * 替换token前缀
51
+     */
52
+    public static String replaceTokenPrefix(String token)
53
+    {
46
         if (StringUtils.isNotEmpty(token) && token.startsWith(CacheConstants.TOKEN_PREFIX))
54
         if (StringUtils.isNotEmpty(token) && token.startsWith(CacheConstants.TOKEN_PREFIX))
47
         {
55
         {
48
             token = token.replace(CacheConstants.TOKEN_PREFIX, "");
56
             token = token.replace(CacheConstants.TOKEN_PREFIX, "");

+ 66 - 0
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ServletUtils.java

@@ -10,11 +10,19 @@ import java.util.Map;
10
 import javax.servlet.http.HttpServletRequest;
10
 import javax.servlet.http.HttpServletRequest;
11
 import javax.servlet.http.HttpServletResponse;
11
 import javax.servlet.http.HttpServletResponse;
12
 import javax.servlet.http.HttpSession;
12
 import javax.servlet.http.HttpSession;
13
+import org.springframework.core.io.buffer.DataBuffer;
14
+import org.springframework.http.HttpHeaders;
15
+import org.springframework.http.HttpStatus;
16
+import org.springframework.http.MediaType;
17
+import org.springframework.http.server.reactive.ServerHttpResponse;
13
 import org.springframework.web.context.request.RequestAttributes;
18
 import org.springframework.web.context.request.RequestAttributes;
14
 import org.springframework.web.context.request.RequestContextHolder;
19
 import org.springframework.web.context.request.RequestContextHolder;
15
 import org.springframework.web.context.request.ServletRequestAttributes;
20
 import org.springframework.web.context.request.ServletRequestAttributes;
21
+import com.alibaba.fastjson.JSONObject;
16
 import com.ruoyi.common.core.constant.Constants;
22
 import com.ruoyi.common.core.constant.Constants;
23
+import com.ruoyi.common.core.domain.R;
17
 import com.ruoyi.common.core.text.Convert;
24
 import com.ruoyi.common.core.text.Convert;
25
+import reactor.core.publisher.Mono;
18
 
26
 
19
 /**
27
 /**
20
  * 客户端工具类
28
  * 客户端工具类
@@ -213,4 +221,62 @@ public class ServletUtils
213
             return "";
221
             return "";
214
         }
222
         }
215
     }
223
     }
224
+
225
+    /**
226
+     * 设置webflux模型响应
227
+     *
228
+     * @param response ServerHttpResponse
229
+     * @param value 响应内容
230
+     * @return Mono<Void>
231
+     */
232
+    public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, Object value)
233
+    {
234
+        return webFluxResponseWriter(response, HttpStatus.OK, value, R.FAIL);
235
+    }
236
+
237
+    /**
238
+     * 设置webflux模型响应
239
+     *
240
+     * @param response ServerHttpResponse
241
+     * @param code 响应状态码
242
+     * @param value 响应内容
243
+     * @return Mono<Void>
244
+     */
245
+    public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, Object value, int code)
246
+    {
247
+        return webFluxResponseWriter(response, HttpStatus.OK, value, code);
248
+    }
249
+
250
+    /**
251
+     * 设置webflux模型响应
252
+     *
253
+     * @param response ServerHttpResponse
254
+     * @param status http状态码
255
+     * @param code 响应状态码
256
+     * @param value 响应内容
257
+     * @return Mono<Void>
258
+     */
259
+    public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, HttpStatus status, Object value, int code)
260
+    {
261
+        return webFluxResponseWriter(response, MediaType.APPLICATION_JSON_VALUE, status, value, code);
262
+    }
263
+
264
+    /**
265
+     * 设置webflux模型响应
266
+     *
267
+     * @param response ServerHttpResponse
268
+     * @param contentType content-type
269
+     * @param status http状态码
270
+     * @param code 响应状态码
271
+     * @param value 响应内容
272
+     * @return Mono<Void>
273
+     */
274
+    public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, String contentType, HttpStatus status, Object value, int code)
275
+    {
276
+        response.setStatusCode(status);
277
+        response.getHeaders().add(HttpHeaders.CONTENT_TYPE, contentType);
278
+        R<?> result = R.fail(code, value.toString());
279
+        DataBuffer dataBuffer = response.bufferFactory().wrap(JSONObject.toJSONString(result).getBytes());
280
+        return response.writeWith(Mono.just(dataBuffer));
281
+    }
216
 }
282
 }

+ 11 - 0
ruoyi-common/ruoyi-common-redis/src/main/java/com/ruoyi/common/redis/service/RedisService.java

@@ -75,6 +75,17 @@ public class RedisService
75
     }
75
     }
76
 
76
 
77
     /**
77
     /**
78
+     * 判断 key是否存在
79
+     *
80
+     * @param key 键
81
+     * @return true 存在 false不存在
82
+     */
83
+    public Boolean hasKey(String key)
84
+    {
85
+        return redisTemplate.hasKey(key);
86
+    }
87
+
88
+    /**
78
      * 获得缓存的基本对象。
89
      * 获得缓存的基本对象。
79
      *
90
      *
80
      * @param key 缓存键值
91
      * @param key 缓存键值

+ 10 - 0
ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java

@@ -73,6 +73,16 @@ public class TokenService
73
     {
73
     {
74
         // 获取请求携带的令牌
74
         // 获取请求携带的令牌
75
         String token = SecurityUtils.getToken(request);
75
         String token = SecurityUtils.getToken(request);
76
+        return getLoginUser(token);
77
+    }
78
+
79
+    /**
80
+     * 获取用户身份信息
81
+     *
82
+     * @return 用户信息
83
+     */
84
+    public LoginUser getLoginUser(String token)
85
+    {
76
         if (StringUtils.isNotEmpty(token))
86
         if (StringUtils.isNotEmpty(token))
77
         {
87
         {
78
             String userKey = getTokenKey(token);
88
             String userKey = getTokenKey(token);

+ 39 - 40
ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/AuthFilter.java

@@ -7,19 +7,15 @@ import org.springframework.beans.factory.annotation.Autowired;
7
 import org.springframework.cloud.gateway.filter.GatewayFilterChain;
7
 import org.springframework.cloud.gateway.filter.GatewayFilterChain;
8
 import org.springframework.cloud.gateway.filter.GlobalFilter;
8
 import org.springframework.cloud.gateway.filter.GlobalFilter;
9
 import org.springframework.core.Ordered;
9
 import org.springframework.core.Ordered;
10
-import org.springframework.core.io.buffer.DataBufferFactory;
11
 import org.springframework.data.redis.core.ValueOperations;
10
 import org.springframework.data.redis.core.ValueOperations;
12
-import org.springframework.http.HttpStatus;
13
-import org.springframework.http.MediaType;
14
 import org.springframework.http.server.reactive.ServerHttpRequest;
11
 import org.springframework.http.server.reactive.ServerHttpRequest;
15
-import org.springframework.http.server.reactive.ServerHttpResponse;
16
 import org.springframework.stereotype.Component;
12
 import org.springframework.stereotype.Component;
17
 import org.springframework.web.server.ServerWebExchange;
13
 import org.springframework.web.server.ServerWebExchange;
18
-import com.alibaba.fastjson.JSON;
19
 import com.alibaba.fastjson.JSONObject;
14
 import com.alibaba.fastjson.JSONObject;
20
 import com.ruoyi.common.core.constant.CacheConstants;
15
 import com.ruoyi.common.core.constant.CacheConstants;
21
 import com.ruoyi.common.core.constant.Constants;
16
 import com.ruoyi.common.core.constant.Constants;
22
-import com.ruoyi.common.core.domain.R;
17
+import com.ruoyi.common.core.constant.HttpStatus;
18
+import com.ruoyi.common.core.utils.SecurityUtils;
23
 import com.ruoyi.common.core.utils.ServletUtils;
19
 import com.ruoyi.common.core.utils.ServletUtils;
24
 import com.ruoyi.common.core.utils.StringUtils;
20
 import com.ruoyi.common.core.utils.StringUtils;
25
 import com.ruoyi.common.redis.service.RedisService;
21
 import com.ruoyi.common.redis.service.RedisService;
@@ -35,7 +31,7 @@ import reactor.core.publisher.Mono;
35
 public class AuthFilter implements GlobalFilter, Ordered
31
 public class AuthFilter implements GlobalFilter, Ordered
36
 {
32
 {
37
     private static final Logger log = LoggerFactory.getLogger(AuthFilter.class);
33
     private static final Logger log = LoggerFactory.getLogger(AuthFilter.class);
38
-    
34
+
39
     private final static long EXPIRE_TIME = Constants.TOKEN_EXPIRE * 60;
35
     private final static long EXPIRE_TIME = Constants.TOKEN_EXPIRE * 60;
40
 
36
 
41
     // 排除过滤的 uri 地址,nacos自行添加
37
     // 排除过滤的 uri 地址,nacos自行添加
@@ -44,61 +40,68 @@ public class AuthFilter implements GlobalFilter, Ordered
44
 
40
 
45
     @Resource(name = "stringRedisTemplate")
41
     @Resource(name = "stringRedisTemplate")
46
     private ValueOperations<String, String> sops;
42
     private ValueOperations<String, String> sops;
47
-    
43
+
48
     @Autowired
44
     @Autowired
49
     private RedisService redisService;
45
     private RedisService redisService;
50
 
46
 
51
     @Override
47
     @Override
52
     public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain)
48
     public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain)
53
     {
49
     {
54
-        String url = exchange.getRequest().getURI().getPath();
50
+        ServerHttpRequest request = exchange.getRequest();
51
+        ServerHttpRequest.Builder mutate = request.mutate();
52
+
53
+        String url = request.getURI().getPath();
55
         // 跳过不需要验证的路径
54
         // 跳过不需要验证的路径
56
         if (StringUtils.matches(url, ignoreWhite.getWhites()))
55
         if (StringUtils.matches(url, ignoreWhite.getWhites()))
57
         {
56
         {
58
             return chain.filter(exchange);
57
             return chain.filter(exchange);
59
         }
58
         }
60
-        String token = getToken(exchange.getRequest());
61
-        if (StringUtils.isBlank(token))
59
+        String token = getToken(request);
60
+        if (StringUtils.isEmpty(token))
62
         {
61
         {
63
-            return setUnauthorizedResponse(exchange, "令牌不能为空");
62
+            return unauthorizedResponse(exchange, "令牌不能为空");
64
         }
63
         }
65
         String userStr = sops.get(getTokenKey(token));
64
         String userStr = sops.get(getTokenKey(token));
66
-        if (StringUtils.isNull(userStr))
65
+        if (StringUtils.isEmpty(userStr))
67
         {
66
         {
68
-            return setUnauthorizedResponse(exchange, "登录状态已过期");
67
+            return unauthorizedResponse(exchange, "登录状态已过期");
69
         }
68
         }
70
-        JSONObject obj = JSONObject.parseObject(userStr);
71
-        String userid = obj.getString("userid");
72
-        String username = obj.getString("username");
73
-        if (StringUtils.isBlank(userid) || StringUtils.isBlank(username))
69
+        JSONObject cacheObj = JSONObject.parseObject(userStr);
70
+        String userid = cacheObj.getString("userid");
71
+        String username = cacheObj.getString("username");
72
+        if (StringUtils.isEmpty(userid) || StringUtils.isEmpty(username))
74
         {
73
         {
75
-            return setUnauthorizedResponse(exchange, "令牌验证失败");
74
+            return unauthorizedResponse(exchange, "令牌验证失败");
76
         }
75
         }
77
-        
76
+
78
         // 设置过期时间
77
         // 设置过期时间
79
         redisService.expire(getTokenKey(token), EXPIRE_TIME);
78
         redisService.expire(getTokenKey(token), EXPIRE_TIME);
80
         // 设置用户信息到请求
79
         // 设置用户信息到请求
81
-        ServerHttpRequest mutableReq = exchange.getRequest().mutate().header(CacheConstants.DETAILS_USER_ID, userid)
82
-                .header(CacheConstants.DETAILS_USERNAME, ServletUtils.urlEncode(username)).build();
83
-        ServerWebExchange mutableExchange = exchange.mutate().request(mutableReq).build();
84
-
85
-        return chain.filter(mutableExchange);
80
+        addHeader(mutate, CacheConstants.DETAILS_USER_ID, userid);
81
+        addHeader(mutate, CacheConstants.DETAILS_USERNAME, username);
82
+        return chain.filter(exchange.mutate().request(mutate.build()).build());
86
     }
83
     }
87
 
84
 
88
-    private Mono<Void> setUnauthorizedResponse(ServerWebExchange exchange, String msg)
85
+    private void addHeader(ServerHttpRequest.Builder mutate, String name, Object value)
89
     {
86
     {
90
-        ServerHttpResponse response = exchange.getResponse();
91
-        response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
92
-        response.setStatusCode(HttpStatus.OK);
87
+        if (value == null)
88
+        {
89
+            return;
90
+        }
91
+        String valueStr = value.toString();
92
+        String valueEncode = ServletUtils.urlEncode(valueStr);
93
+        mutate.header(name, valueEncode);
94
+    }
93
 
95
 
96
+    private Mono<Void> unauthorizedResponse(ServerWebExchange exchange, String msg)
97
+    {
94
         log.error("[鉴权异常处理]请求路径:{}", exchange.getRequest().getPath());
98
         log.error("[鉴权异常处理]请求路径:{}", exchange.getRequest().getPath());
95
-
96
-        return response.writeWith(Mono.fromSupplier(() -> {
97
-            DataBufferFactory bufferFactory = response.bufferFactory();
98
-            return bufferFactory.wrap(JSON.toJSONBytes(R.fail(HttpStatus.UNAUTHORIZED.value(), msg)));
99
-        }));
99
+        return ServletUtils.webFluxResponseWriter(exchange.getResponse(), msg, HttpStatus.UNAUTHORIZED);
100
     }
100
     }
101
 
101
 
102
+    /**
103
+     * 获取缓存key
104
+     */
102
     private String getTokenKey(String token)
105
     private String getTokenKey(String token)
103
     {
106
     {
104
         return CacheConstants.LOGIN_TOKEN_KEY + token;
107
         return CacheConstants.LOGIN_TOKEN_KEY + token;
@@ -109,12 +112,8 @@ public class AuthFilter implements GlobalFilter, Ordered
109
      */
112
      */
110
     private String getToken(ServerHttpRequest request)
113
     private String getToken(ServerHttpRequest request)
111
     {
114
     {
112
-        String token = request.getHeaders().getFirst(CacheConstants.HEADER);
113
-        if (StringUtils.isNotEmpty(token) && token.startsWith(CacheConstants.TOKEN_PREFIX))
114
-        {
115
-            token = token.replace(CacheConstants.TOKEN_PREFIX, "");
116
-        }
117
-        return token;
115
+        String token = request.getHeaders().getFirst(CacheConstants.TOKEN_AUTHENTICATION);
116
+        return SecurityUtils.replaceTokenPrefix(token);
118
     }
117
     }
119
 
118
 
120
     @Override
119
     @Override

+ 2 - 8
ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/BlackListUrlFilter.java

@@ -5,11 +5,8 @@ import java.util.List;
5
 import java.util.regex.Pattern;
5
 import java.util.regex.Pattern;
6
 import org.springframework.cloud.gateway.filter.GatewayFilter;
6
 import org.springframework.cloud.gateway.filter.GatewayFilter;
7
 import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
7
 import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
8
-import org.springframework.http.server.reactive.ServerHttpResponse;
9
 import org.springframework.stereotype.Component;
8
 import org.springframework.stereotype.Component;
10
-import com.alibaba.fastjson.JSON;
11
-import com.ruoyi.common.core.web.domain.AjaxResult;
12
-import reactor.core.publisher.Mono;
9
+import com.ruoyi.common.core.utils.ServletUtils;
13
 
10
 
14
 /**
11
 /**
15
  * 黑名单过滤器
12
  * 黑名单过滤器
@@ -27,10 +24,7 @@ public class BlackListUrlFilter extends AbstractGatewayFilterFactory<BlackListUr
27
             String url = exchange.getRequest().getURI().getPath();
24
             String url = exchange.getRequest().getURI().getPath();
28
             if (config.matchBlacklist(url))
25
             if (config.matchBlacklist(url))
29
             {
26
             {
30
-                ServerHttpResponse response = exchange.getResponse();
31
-                response.getHeaders().add("Content-Type", "application/json;charset=UTF-8");
32
-                return exchange.getResponse().writeWith(
33
-                        Mono.just(response.bufferFactory().wrap(JSON.toJSONBytes(AjaxResult.error("请求地址不允许访问")))));
27
+                return ServletUtils.webFluxResponseWriter(exchange.getResponse(), "请求地址不允许访问");
34
             }
28
             }
35
 
29
 
36
             return chain.filter(exchange);
30
             return chain.filter(exchange);

+ 2 - 8
ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/ValidateCodeFilter.java

@@ -9,16 +9,13 @@ import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFac
9
 import org.springframework.core.io.buffer.DataBuffer;
9
 import org.springframework.core.io.buffer.DataBuffer;
10
 import org.springframework.core.io.buffer.DataBufferUtils;
10
 import org.springframework.core.io.buffer.DataBufferUtils;
11
 import org.springframework.http.server.reactive.ServerHttpRequest;
11
 import org.springframework.http.server.reactive.ServerHttpRequest;
12
-import org.springframework.http.server.reactive.ServerHttpResponse;
13
 import org.springframework.stereotype.Component;
12
 import org.springframework.stereotype.Component;
14
-import com.alibaba.fastjson.JSON;
15
 import com.alibaba.fastjson.JSONObject;
13
 import com.alibaba.fastjson.JSONObject;
14
+import com.ruoyi.common.core.utils.ServletUtils;
16
 import com.ruoyi.common.core.utils.StringUtils;
15
 import com.ruoyi.common.core.utils.StringUtils;
17
-import com.ruoyi.common.core.web.domain.AjaxResult;
18
 import com.ruoyi.gateway.config.properties.CaptchaProperties;
16
 import com.ruoyi.gateway.config.properties.CaptchaProperties;
19
 import com.ruoyi.gateway.service.ValidateCodeService;
17
 import com.ruoyi.gateway.service.ValidateCodeService;
20
 import reactor.core.publisher.Flux;
18
 import reactor.core.publisher.Flux;
21
-import reactor.core.publisher.Mono;
22
 
19
 
23
 /**
20
 /**
24
  * 验证码过滤器
21
  * 验证码过滤器
@@ -60,10 +57,7 @@ public class ValidateCodeFilter extends AbstractGatewayFilterFactory<Object>
60
             }
57
             }
61
             catch (Exception e)
58
             catch (Exception e)
62
             {
59
             {
63
-                ServerHttpResponse response = exchange.getResponse();
64
-                response.getHeaders().add("Content-Type", "application/json;charset=UTF-8");
65
-                return exchange.getResponse().writeWith(
66
-                        Mono.just(response.bufferFactory().wrap(JSON.toJSONBytes(AjaxResult.error(e.getMessage())))));
60
+                return ServletUtils.webFluxResponseWriter(exchange.getResponse(), e.getMessage());
67
             }
61
             }
68
             return chain.filter(exchange);
62
             return chain.filter(exchange);
69
         };
63
         };

+ 2 - 12
ruoyi-gateway/src/main/java/com/ruoyi/gateway/handler/GatewayExceptionHandler.java

@@ -6,14 +6,10 @@ import org.slf4j.LoggerFactory;
6
 import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler;
6
 import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler;
7
 import org.springframework.context.annotation.Configuration;
7
 import org.springframework.context.annotation.Configuration;
8
 import org.springframework.core.annotation.Order;
8
 import org.springframework.core.annotation.Order;
9
-import org.springframework.core.io.buffer.DataBufferFactory;
10
-import org.springframework.http.HttpStatus;
11
-import org.springframework.http.MediaType;
12
 import org.springframework.http.server.reactive.ServerHttpResponse;
9
 import org.springframework.http.server.reactive.ServerHttpResponse;
13
 import org.springframework.web.server.ResponseStatusException;
10
 import org.springframework.web.server.ResponseStatusException;
14
 import org.springframework.web.server.ServerWebExchange;
11
 import org.springframework.web.server.ServerWebExchange;
15
-import com.alibaba.fastjson.JSON;
16
-import com.ruoyi.common.core.domain.R;
12
+import com.ruoyi.common.core.utils.ServletUtils;
17
 import reactor.core.publisher.Mono;
13
 import reactor.core.publisher.Mono;
18
 
14
 
19
 /**
15
 /**
@@ -55,12 +51,6 @@ public class GatewayExceptionHandler implements ErrorWebExceptionHandler
55
 
51
 
56
         log.error("[网关异常处理]请求路径:{},异常信息:{}", exchange.getRequest().getPath(), ex.getMessage());
52
         log.error("[网关异常处理]请求路径:{},异常信息:{}", exchange.getRequest().getPath(), ex.getMessage());
57
 
53
 
58
-        response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
59
-        response.setStatusCode(HttpStatus.OK);
60
-
61
-        return response.writeWith(Mono.fromSupplier(() -> {
62
-            DataBufferFactory bufferFactory = response.bufferFactory();
63
-            return bufferFactory.wrap(JSON.toJSONBytes(R.fail(msg)));
64
-        }));
54
+        return ServletUtils.webFluxResponseWriter(response, msg);
65
     }
55
     }
66
 }
56
 }

+ 2 - 8
ruoyi-gateway/src/main/java/com/ruoyi/gateway/handler/SentinelFallbackHandler.java

@@ -1,10 +1,8 @@
1
 package com.ruoyi.gateway.handler;
1
 package com.ruoyi.gateway.handler;
2
 
2
 
3
-import java.nio.charset.StandardCharsets;
4
 import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.GatewayCallbackManager;
3
 import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.GatewayCallbackManager;
5
 import com.alibaba.csp.sentinel.slots.block.BlockException;
4
 import com.alibaba.csp.sentinel.slots.block.BlockException;
6
-import org.springframework.core.io.buffer.DataBuffer;
7
-import org.springframework.http.server.reactive.ServerHttpResponse;
5
+import com.ruoyi.common.core.utils.ServletUtils;
8
 import org.springframework.web.reactive.function.server.ServerResponse;
6
 import org.springframework.web.reactive.function.server.ServerResponse;
9
 import org.springframework.web.server.ServerWebExchange;
7
 import org.springframework.web.server.ServerWebExchange;
10
 import org.springframework.web.server.WebExceptionHandler;
8
 import org.springframework.web.server.WebExceptionHandler;
@@ -19,11 +17,7 @@ public class SentinelFallbackHandler implements WebExceptionHandler
19
 {
17
 {
20
     private Mono<Void> writeResponse(ServerResponse response, ServerWebExchange exchange)
18
     private Mono<Void> writeResponse(ServerResponse response, ServerWebExchange exchange)
21
     {
19
     {
22
-        ServerHttpResponse serverHttpResponse = exchange.getResponse();
23
-        serverHttpResponse.getHeaders().add("Content-Type", "application/json;charset=UTF-8");
24
-        byte[] datas = "{\"code\":429,\"msg\":\"请求超过最大数,请稍后再试\"}".getBytes(StandardCharsets.UTF_8);
25
-        DataBuffer buffer = serverHttpResponse.bufferFactory().wrap(datas);
26
-        return serverHttpResponse.writeWith(Mono.just(buffer));
20
+        return ServletUtils.webFluxResponseWriter(exchange.getResponse(), "请求超过最大数,请稍后再试");
27
     }
21
     }
28
 
22
 
29
     @Override
23
     @Override

+ 9 - 9
ruoyi-ui/src/utils/ruoyi.js

@@ -185,15 +185,15 @@ export function tansParams(params) {
185
         var part = encodeURIComponent(propName) + "=";
185
         var part = encodeURIComponent(propName) + "=";
186
         if (value !== null && typeof(value) !== "undefined") {
186
         if (value !== null && typeof(value) !== "undefined") {
187
             if (typeof value === 'object') {
187
             if (typeof value === 'object') {
188
-				for (const key of Object.keys(value)) {
189
-					let params = propName + '[' + key + ']';
190
-					var subPart = encodeURIComponent(params) + "=";
191
-					result += subPart + encodeURIComponent(value[key]) + "&";
192
-				}
188
+                for (const key of Object.keys(value)) {
189
+                    let params = propName + '[' + key + ']';
190
+                    var subPart = encodeURIComponent(params) + "=";
191
+                    result += subPart + encodeURIComponent(value[key]) + "&";
192
+                }
193
             } else {
193
             } else {
194
-				result += part + encodeURIComponent(value) + "&";
195
-            }
196
-		}
194
+                result += part + encodeURIComponent(value) + "&";
195
+           }
196
+        }
197
     }
197
     }
198
-	return result
198
+    return result
199
 }
199
 }