当前位置:网站首页>2022-06-07 ResponseBodyAdvice导致Swagger出现弹框问题
2022-06-07 ResponseBodyAdvice导致Swagger出现弹框问题
2022-07-28 05:26:00 【不爱吃奶昔】
出现问题

由于全局响应统一处理实现ResponseBodyAdvice造成swagger “/swagger-resources/configuration/ui”、“/swagger-resources/configuration/security”、"/swagger-resources"请求,由json格式变成自定义响应体导致无法显示。
解决办法
对全局响应统一处理添加basePackages限制:

/** * 全局统一返回处理 * * @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) {
// 返回 true则执行 beforeBodyWrite方法,
// 返回类型不是 ResponseResult,且没有 @NotResponseBody注解,会执行
return !returnType.getParameterType().equals(ResponseResult.class) && !returnType.hasMethodAnnotation(NotResponseBody.class);
}
/** * 处理返回信息,并保存访问日志返回code和msg */
@Override
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
// 若为 String类型,则直接返回 json字符串
if (returnType.getGenericParameterType().equals(String.class)) {
SystemLogContextHolder.get().setRespCode(2000).setRespMsg("");
return JsonUtil.obj2Str(body);
}
return ResponseResult.success(body);
}
}
边栏推荐
- Matlab simulation of radar imaging 2 - pulse compression and windowing
- 自定义组件--纯数据字段&组件的生命周期
- Use and safe shutdown of qthread thread in QT
- pyppeteer 下拉 selenium下拉
- QT painting event - set background picture
- Five categories of IP addresses
- Vs code basic configuration and beautification
- 【学习笔记】进程创建
- EMC experiment practical case ESD electrostatic experiment
- qt解决每次修改完ui文件都要重新构建的问题
猜你喜欢
随机推荐
MySQL delete tables without deleting databases
What about the insufficient memory of Clickhouse aggregation? Then improve the polymerization performance
OpenGL quick configuration method
Icc2 (III) clock tree synthesis
QT implementation outputs relevant information to log file
Servlet
多个ics日历合并成单个ics日历
Five categories of IP addresses
[server usage record] log in to the remote server through the springboard machine and transfer files
Systemmediasize startup option added in esxi 7.0 update 1C
Introduction to Perl (IX) quotation
微信小程序自定义编译模式
Get the current directory in QT
qt解析字符串转为json数据并解析
clickhouse聚合之内存不足怎么办?那就提升聚合性能
JSP实现文件上传功能的同时还要向后台传递参数
Pytorch learning note 4 - automatic calculation of gradient descent autograd
qt中获取当前目录
我的部署笔记
新的selenium









