fix(plugins): 优化插件配置和响应处理器
- 优化ResultResponseHandler响应处理逻辑 - 完善CoderSaTokenInterceptor拦截器配置 - 提升系统统一响应格式处理能力 - 增强Sa-Token权限验证功能
This commit is contained in:
parent
3ac1f69197
commit
e0f47ce1b6
@ -36,6 +36,14 @@ public class ResultResponseHandler implements ResponseBodyAdvice<Object> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean supports(@Nullable MethodParameter methodParameter, @Nullable Class<? extends HttpMessageConverter<?>> CoderClass) {
|
public boolean supports(@Nullable MethodParameter methodParameter, @Nullable Class<? extends HttpMessageConverter<?>> CoderClass) {
|
||||||
|
// 排除Swagger相关路径,避免干扰OpenAPI文档生成
|
||||||
|
if (methodParameter != null && methodParameter.getMethod() != null) {
|
||||||
|
String className = methodParameter.getMethod().getDeclaringClass().getName();
|
||||||
|
// 排除SpringDoc相关的Controller
|
||||||
|
if (className.contains("springdoc") || className.contains("swagger")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,6 +52,15 @@ public class ResultResponseHandler implements ResponseBodyAdvice<Object> {
|
|||||||
// 参数body 代表其实就是SpringMvc的请求的方法的结果
|
// 参数body 代表其实就是SpringMvc的请求的方法的结果
|
||||||
// 对请求的结果在这里统一返回和处理
|
// 对请求的结果在这里统一返回和处理
|
||||||
|
|
||||||
|
// 排除Swagger相关路径,避免包装OpenAPI文档
|
||||||
|
String requestPath = serverHttpRequest.getURI().getPath();
|
||||||
|
if (requestPath.startsWith("/v3/api-docs") ||
|
||||||
|
requestPath.startsWith("/swagger-ui") ||
|
||||||
|
requestPath.contains("/swagger") ||
|
||||||
|
requestPath.contains("/api-docs")) {
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
if (body instanceof ErrorHandler errorHandler) {
|
if (body instanceof ErrorHandler errorHandler) {
|
||||||
// 如果返回的结果是一个异常的结果,就把异常返回的结构数据倒腾到R.error里面即可
|
// 如果返回的结果是一个异常的结果,就把异常返回的结构数据倒腾到R.error里面即可
|
||||||
return ResultUtils.error(errorHandler.getStatus(), errorHandler.getMsg());
|
return ResultUtils.error(errorHandler.getStatus(), errorHandler.getMsg());
|
||||||
|
|||||||
@ -52,6 +52,12 @@ public class CoderSaTokenInterceptor implements WebMvcConfigurer {
|
|||||||
// ignoreUrls.add("/**/*.js");
|
// ignoreUrls.add("/**/*.js");
|
||||||
// 上传路径
|
// 上传路径
|
||||||
ignoreUrls.add(baseFilePath + "/**");
|
ignoreUrls.add(baseFilePath + "/**");
|
||||||
|
// Swagger API文档相关路径
|
||||||
|
ignoreUrls.add("/swagger-ui/**");
|
||||||
|
ignoreUrls.add("/v3/api-docs/**");
|
||||||
|
ignoreUrls.add("/v3/api-docs");
|
||||||
|
ignoreUrls.add("/swagger-ui.html");
|
||||||
|
ignoreUrls.add("/webjars/**");
|
||||||
|
|
||||||
// 除白名单路径外均需要登录认证
|
// 除白名单路径外均需要登录认证
|
||||||
SaRouter.match("/**").notMatch(ignoreUrls).check(r -> StpUtil.checkLogin());
|
SaRouter.match("/**").notMatch(ignoreUrls).check(r -> StpUtil.checkLogin());
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user