问题展示
swagger的访问请求到了supports中会被拦截下来,因为ResponseBodyAdvice是拦截@RestController注解,swagger中也有这个注解,所以swagger会被拦截下来
问题解决第一种方式
@InitBinder
public void binder(WebDataBinder webDataBinder){
StringTrimmerEditor propertyEditor = new StringTrimmerEditor(false);
webDataBinder.registerCustomEditor(String.class, propertyEditor);
}
!methodParameter.getDeclaringClass().getName().contains("springfox")
问题解决第二种方式
创建注解
package com.rj.bd.Config;
import java.lang.annotation.*;
/**
* @author lisuo
* @version 1.0
* @Description
* @email 495019733@qq.com
* @date 2021/11/30 1:02
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.METHOD})
@Documented
public @interface ResponseResult {
/**
* @Target 说明了Annotation所修饰的对象范围:Annotation可被用于 packages、types(类、接口、枚举、Annotation类型)、类型成员(方法、构造方法、成员变量、枚举值)、方法参数和本地变量(如循环变量、catch参数)。在Annotation类型的声明中使用了target可更加明晰其修饰的目标。
* 作用:用于描述注解的使用范围(即:被描述的注解可以用在什么地方)
* 1.CONSTRUCTOR:用于描述构造器
* 2.FIELD:用于描述域
* 3.LOCAL_VARIABLE:用于描述局部变量
* 4.METHOD:用于描述方法
* 5.PACKAGE:用于描述包
* 6.PARAMETER:用于描述参数
* 7.TYPE:用于描述类、接口(包括注解类型) 或enum声明
*
*
* 1、RetentionPolicy.SOURCE:注解只保留在源文件,当Java文件编译成class文件的时候,注解被遗弃;
* 2、RetentionPolicy.CLASS:注解被保留到class文件,但jvm加载class文件时候被遗弃,这是默认的生命周期;
* 3、RetentionPolicy.RUNTIME:注解不仅被保存到class文件中,jvm加载class文件之后,仍然存在;
*
* 这3个生命周期分别对应于:Java源文件(.java文件) ---> .class文件 ---> 内存中的字节码。
*
* 如果一个注解@B,被@Documented标注,那么被@B修饰的类,生成文档时,会显示@B。如果@B没有被@Documented标准,最终生成的文档中就不会显示@B。
* 我们来看一些文档示例:
*/
}
@InitBinder
public void binder(WebDataBinder webDataBinder){
StringTrimmerEditor propertyEditor = new StringTrimmerEditor(false);
webDataBinder.registerCustomEditor(String.class, propertyEditor);
}
-
设置只过滤我们刚才创建得到注解。前提是你的Controller层需要协商这个注解
-
现在可以正常访问了