content: package com.newone.mall.admin.config;
  
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.context.annotation.Profile;
  import springfox.documentation.builders.ApiInfoBuilder;
  import springfox.documentation.builders.PathSelectors;
  import springfox.documentation.builders.RequestHandlerSelectors;
  import springfox.documentation.service.ApiInfo;
  import springfox.documentation.service.Contact;
  import springfox.documentation.spi.DocumentationType;
  import springfox.documentation.spring.web.plugins.Docket;
  import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
  
  @Configuration
  @EnableSwagger2WebMvc
  @Profile("dev") // 只在 dev 环境中开启
  public class Knife4jAdminConfig {
      @Bean("adminApi")
      public Docket createApiDoc() {
          Docket docket = new Docket(DocumentationType.SWAGGER_2)
                  .apiInfo(buildApiInfo())
                  // 分组名称
                  .groupName("Admin 前台接口")
                  .select()
                  // 这里指定 Controller 扫描包路径
                  .apis(RequestHandlerSelectors.basePackage("com.newone.mall.admin.controller"))
                  .paths(PathSelectors.any())
                  .build();
          return docket;
      }
  
      /**
       * 构建 API 信息
       *
       * @return
       */
      private ApiInfo buildApiInfo() {
          return new ApiInfoBuilder()
                  .title("Mall 购物商城管理员后台接口文档") // 标题
                  .description("Mall 是一款由 Spring Boot + Vue 3.2 + Vite 4.3 开发的前后端分离购物商城。") // 描述
                  .termsOfServiceUrl("https://www.newonehow.com/") // API 服务条款
                  .contact(new Contact("NewOne", "https://www.newonehow.com", "howonenew@163.com")) // 联系人
                  .version("1.0") // 版本号
                  .build();
      }
  }
  