导入依赖
1 <dependency> 2 <groupId>com.github.xiaoymin</groupId> 3 <artifactId>knife4j-spring-boot-starter</artifactId> 4 <version>3.0.3</version> 5 </dependency>
配置代码
1 @Configuration 2 @EnableSwagger2WebMvc 3 public class Knife4jConfig { 4 5 @Bean 6 public Docket adminApiConfig(){ 7 List<Parameter> pars = new ArrayList<>(); 8 ParameterBuilder tokenPar = new ParameterBuilder(); 9 tokenPar.name("token") 10 .description("用户token") 11 .defaultValue("") 12 .modelRef(new ModelRef("string")) 13 .parameterType("header") 14 .required(false) 15 .build(); 16 pars.add(tokenPar.build()); 17 //添加head参数end 18 19 Docket adminApi = new Docket(DocumentationType.SWAGGER_2) 20 .groupName("adminApi") 21 .apiInfo(adminApiInfo()) 22 .select() 23 //只显示admin路径下的页面 24 .apis(RequestHandlerSelectors.basePackage("com.atguigu")) 25 .paths(PathSelectors.regex("/admin/.*")) 26 .build() 27 .globalOperationParameters(pars); 28 return adminApi; 29 } 30 31 private ApiInfo adminApiInfo(){ 32 33 return new ApiInfoBuilder() 34 .title("后台管理系统-API文档") 35 .description("本文档描述了后台管理系统微服务接口定义") 36 .version("1.0") 37 .contact(new Contact("atguigu", "http://atguigu.com", "[email protected]")) 38 .build(); 39 } 40 41 42 }
标签:tokenPar,knife4j,adminApi,接口,build,atguigu,new,swagger,com From: https://www.cnblogs.com/qijiangforever/p/17419133.html