当前位置:网站首页>2022-06-07 responsebodyadvice caused the spring frame problem in swagger
2022-06-07 responsebodyadvice caused the spring frame problem in swagger
2022-07-28 06:35:00 【Don't like milkshakes】
ResponseBodyAdvice Lead to Swagger Pop up problem
Problems arise

Due to the unified processing of global response ResponseBodyAdvice cause swagger “/swagger-resources/configuration/ui”、“/swagger-resources/configuration/security”、"/swagger-resources" request , from json The format becomes a custom response body, which makes it impossible to display .
terms of settlement
Add basePackages Limit :

/** * Global unified return processing * * @Author zsl * @Date 2022/5/15 19:10 * @Email [email protected] */
@ControllerAdvice(basePackages = "com.zsl.custombox.authentication.controller")
@Order(Integer.MAX_VALUE - 20)
public class GlobalResponseResultAdvice implements ResponseBodyAdvice<Object> {
@Override
public boolean supports(MethodParameter returnType, Class converterType) {
// return true execute beforeBodyWrite Method ,
// Return type is not ResponseResult, And there's no @NotResponseBody annotation , Will execute
return !returnType.getParameterType().equals(ResponseResult.class) && !returnType.hasMethodAnnotation(NotResponseBody.class);
}
/** * Process the returned information , Save the access log and return code and msg */
@Override
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
// if String type , Then return directly json character string
if (returnType.getGenericParameterType().equals(String.class)) {
SystemLogContextHolder.get().setRespCode(2000).setRespMsg("");
return JsonUtil.obj2Str(body);
}
return ResponseResult.success(body);
}
}
Reference article : Project implementation ResponseBodyAdvice Lead to swagger abnormal
边栏推荐
- 气导贴耳式耳机推荐、不需要佩戴入耳的气传导耳机
- Word邮件合并功能详解:合并后生成多个word文档,删除空白页
- Matlab simulation of radar imaging 3 - multi-target detection
- Word自动目录字体修改和行间距的问题
- 量化交易机器人系统开发
- 根据IP地址和子网掩码求主机所在的网络地址和广播地址
- QT parse string into JSON data and parse
- QT batch operation control and set signal slot
- ubuntu mysql 设置远程访问权限
- qt中Qthread线程的使用以及安全关闭
猜你喜欢

Cautious speculation about fusion on Apple silicon

mysql join技巧

MySQL join skills

JSON笔记

Detailed explanation of word mail merge function: after merging, multiple word documents are generated and blank pages are deleted

Combine multiple ICs calendars into a single ICs calendar

QT batch operation control and set signal slot

OpenGL quick configuration method

qt自定义滑动按钮(美观且使用方便)
![[yolov5] environment construction: win11 + mx450](/img/04/4da9b3748d5f45ef73cffcc48f8609.png)
[yolov5] environment construction: win11 + mx450
随机推荐
Overall understanding of PLC
Listener
Talking about fluke optical cable certification? What is CFP? What is OFP?
夹子套利/搬砖套利系统开发
保研面试中常见的英语问题有哪些?
【学习笔记】进程创建
自定义组件--样式
Perl Introduction (10) formatted output
[untitled]
Perl introductory learning (VIII) subroutine
相对路径和绝对路径
Detailed explanation of word mail merge function: after merging, multiple word documents are generated and blank pages are deleted
当前学习进度
gerapy 使用
2021-11-10
Pyppeteer 被识别 绕过检测
Matlab simulation of radar imaging 2 - pulse compression and windowing
Perl introductory learning (XI) file operation
【学习笔记】编码能力
qt自定义滑动按钮(美观且使用方便)