| @@ -0,0 +1,29 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | |||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |||
| <parent> | |||
| <artifactId>mallink</artifactId> | |||
| <groupId>com.iformall</groupId> | |||
| <version>1.0</version> | |||
| </parent> | |||
| <modelVersion>4.0.0</modelVersion> | |||
| <artifactId>mallink-swagger</artifactId> | |||
| <dependencies> | |||
| <!--swagger 相关依赖--> | |||
| <dependency> | |||
| <groupId>io.springfox</groupId> | |||
| <artifactId>springfox-swagger2</artifactId> | |||
| <version>2.9.2</version> | |||
| </dependency> | |||
| <!--doc.html模式--> | |||
| <dependency> | |||
| <groupId>com.github.xiaoymin</groupId> | |||
| <artifactId>swagger-bootstrap-ui</artifactId> | |||
| <version>1.9.3</version> | |||
| </dependency> | |||
| </dependencies> | |||
| </project> | |||
| @@ -0,0 +1,19 @@ | |||
| package com.iformall.annotation; | |||
| import java.lang.annotation.ElementType; | |||
| import java.lang.annotation.Retention; | |||
| import java.lang.annotation.RetentionPolicy; | |||
| import java.lang.annotation.Target; | |||
| @Target(ElementType.METHOD) | |||
| @Retention(RetentionPolicy.RUNTIME) | |||
| public @interface ApiVersion { | |||
| /** | |||
| * 接口版本号(对应swagger中的group) | |||
| * | |||
| * @return String[] | |||
| */ | |||
| String[] group(); | |||
| } | |||
| @@ -0,0 +1,14 @@ | |||
| package com.iformall.annotation; | |||
| import com.iformall.config.SwaggerConfiguration; | |||
| import org.springframework.context.annotation.Import; | |||
| import java.lang.annotation.*; | |||
| @Target({ElementType.TYPE}) | |||
| @Retention(RetentionPolicy.RUNTIME) | |||
| @Documented | |||
| @Inherited | |||
| @Import({SwaggerConfiguration.class}) | |||
| public @interface BaseEnableSwagger { | |||
| } | |||
| @@ -0,0 +1,53 @@ | |||
| package com.iformall.config; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.beans.factory.annotation.Value; | |||
| import org.springframework.stereotype.Component; | |||
| import springfox.documentation.swagger.web.SwaggerResource; | |||
| import springfox.documentation.swagger.web.SwaggerResourcesProvider; | |||
| import java.util.ArrayList; | |||
| import java.util.HashSet; | |||
| import java.util.List; | |||
| import java.util.Set; | |||
| @Component | |||
| public class ParkingSwaggerResourcesProvider implements SwaggerResourcesProvider { | |||
| /** | |||
| * swagger2 的特定资源地址 | |||
| */ | |||
| private static final String SWAGGER2URL = "/v2/api-docs"; | |||
| /** | |||
| * 本应用名称,下文需要将自己排除掉 | |||
| */ | |||
| @Value("${spring.application.name}") | |||
| private String curApplicationName; | |||
| @Autowired | |||
| private SwaggerProperties swaggerProperties; | |||
| @Override | |||
| public List<SwaggerResource> get() { | |||
| List<SwaggerResource> resources = new ArrayList<>(); | |||
| List<String> routeHosts = new ArrayList<>(); | |||
| Set<String> allUrls = new HashSet<>(); | |||
| routeHosts.forEach(instance -> { | |||
| // /serviceId/v2/api-info,当网关调用这个接口时,会自动寻找对应的服务实例 | |||
| String url = "/" + instance + SWAGGER2URL; | |||
| if (!allUrls.contains(url)) { | |||
| allUrls.add(url); | |||
| SwaggerResource swaggerResource = new SwaggerResource(); | |||
| swaggerResource.setUrl(url); | |||
| //swaggerResource.setLocation(url);location 已过期,直接采用 url 代替 | |||
| swaggerResource.setName(instance); | |||
| resources.add(swaggerResource); | |||
| } | |||
| }); | |||
| return resources; | |||
| } | |||
| } | |||
| @@ -0,0 +1,132 @@ | |||
| package com.iformall.config; | |||
| import com.google.common.base.Predicate; | |||
| import com.google.common.base.Predicates; | |||
| import com.iformall.annotation.ApiVersion; | |||
| import com.iformall.constant.SwaggerConstant; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.beans.factory.support.DefaultListableBeanFactory; | |||
| import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | |||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | |||
| import org.springframework.boot.context.properties.EnableConfigurationProperties; | |||
| import org.springframework.context.annotation.Bean; | |||
| import org.springframework.context.annotation.Configuration; | |||
| import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; | |||
| import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; | |||
| import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | |||
| import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; | |||
| 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.paths.RelativePathProvider; | |||
| import springfox.documentation.spring.web.plugins.Docket; | |||
| import springfox.documentation.swagger2.annotations.EnableSwagger2; | |||
| import javax.servlet.ServletContext; | |||
| import java.util.ArrayList; | |||
| import java.util.Arrays; | |||
| import java.util.List; | |||
| @Configuration | |||
| @EnableSwagger2 | |||
| @EnableAutoConfiguration | |||
| @EnableConfigurationProperties(SwaggerProperties.class) | |||
| @ConditionalOnProperty(name = "swagger.enabled", matchIfMissing = true) | |||
| public class SwaggerConfiguration { | |||
| private static final List<String> DEFAULT_EXCLUDE_PATH = Arrays.asList("/error"); | |||
| private static final String BASE_PATH = "/**"; | |||
| @Autowired | |||
| private SwaggerProperties swaggerProperties; | |||
| private DefaultListableBeanFactory context; | |||
| private RequestMappingHandlerMapping handlerMapping; | |||
| public SwaggerConfiguration(DefaultListableBeanFactory context, | |||
| RequestMappingHandlerMapping handlerMapping) { | |||
| this.context = context; | |||
| this.handlerMapping = handlerMapping; | |||
| dynamicCreate(); | |||
| } | |||
| private void dynamicCreate() { | |||
| // swaggerProperties.getServices().forEach(item -> { | |||
| // api(item); | |||
| // | |||
| // }); | |||
| } | |||
| @Bean | |||
| public Docket api(ServletContext servletContext) { | |||
| // base-path处理 | |||
| if (swaggerProperties.getBasePath().isEmpty()) { | |||
| swaggerProperties.getBasePath().add(BASE_PATH); | |||
| } | |||
| List<Predicate<String>> basePath = new ArrayList<>(swaggerProperties.getBasePath().size()); | |||
| swaggerProperties.getBasePath().forEach(path -> basePath.add(PathSelectors.ant(path))); | |||
| // exclude-path处理 | |||
| if (swaggerProperties.getExcludePath().isEmpty()) { | |||
| swaggerProperties.getExcludePath().addAll(DEFAULT_EXCLUDE_PATH); | |||
| } | |||
| List<Predicate<String>> excludePath = new ArrayList<>(); | |||
| swaggerProperties.getExcludePath().forEach(path -> excludePath.add(PathSelectors.ant(path))); | |||
| return new Docket(DocumentationType.SWAGGER_2) | |||
| .host(swaggerProperties.getHost() + "/B") | |||
| .apiInfo(apiInfo(swaggerProperties)).select() | |||
| .apis(RequestHandlerSelectors.basePackage(swaggerProperties.getBasePackage())) | |||
| .apis(input -> { | |||
| ApiVersion apiVersion = input.getHandlerMethod().getMethodAnnotation(ApiVersion.class); | |||
| return apiVersion != null && Arrays.asList(apiVersion.group()).contains(SwaggerConstant.V_1_0_0); | |||
| }) | |||
| .paths( | |||
| Predicates.and( | |||
| Predicates.not(Predicates.or(excludePath)), | |||
| Predicates.or(basePath) | |||
| ) | |||
| ) | |||
| .build().groupName("a") | |||
| .pathMapping("/B"); | |||
| } | |||
| private ApiInfo apiInfo(SwaggerProperties swaggerProperties) { | |||
| return new ApiInfoBuilder() | |||
| .title(swaggerProperties.getTitle()) | |||
| .description(swaggerProperties.getDescription()) | |||
| .license(swaggerProperties.getLicense()) | |||
| .licenseUrl(swaggerProperties.getLicenseUrl()) | |||
| .termsOfServiceUrl(swaggerProperties.getTermsOfServiceUrl()) | |||
| .contact(new Contact(swaggerProperties.getContact().getName(), swaggerProperties.getContact().getUrl(), swaggerProperties.getContact().getEmail())) | |||
| .version(swaggerProperties.getVersion()) | |||
| .build(); | |||
| } | |||
| // @Override | |||
| // public void addViewControllers(ViewControllerRegistry registry) { | |||
| // String prePath = swaggerProperties.getPrePath(); | |||
| // String apiDocs = "/v2/api-docs"; | |||
| // String configUi = "/swagger-resources/configuration/ui"; | |||
| // String configSecurity = "/swagger-resources/configuration/security"; | |||
| // String resources = "/swagger-resources"; | |||
| // | |||
| // registry.addRedirectViewController(prePath + apiDocs, apiDocs).setKeepQueryParams(true); | |||
| // registry.addRedirectViewController(prePath + resources, resources); | |||
| // registry.addRedirectViewController(prePath + configUi, configUi); | |||
| // registry.addRedirectViewController(prePath + configSecurity, configSecurity); | |||
| // registry.addRedirectViewController(prePath, "/"); | |||
| // } | |||
| // | |||
| // @Override | |||
| // public void addResourceHandlers(ResourceHandlerRegistry registry) { | |||
| // registry.addResourceHandler(swaggerProperties.getPrePath() + "/**") | |||
| // .addResourceLocations("classpath:/META-INF/resources/"); | |||
| // } | |||
| } | |||
| @@ -0,0 +1,81 @@ | |||
| package com.iformall.config; | |||
| import lombok.Data; | |||
| import org.springframework.boot.context.properties.ConfigurationProperties; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| @Data | |||
| @ConfigurationProperties("swagger") | |||
| public class SwaggerProperties { | |||
| private Map<String, String> services; | |||
| private String prePath; | |||
| /** | |||
| * 是否开启swagger | |||
| */ | |||
| private Boolean enabled; | |||
| /** | |||
| * swagger会解析的包路径 | |||
| **/ | |||
| private String basePackage = ""; | |||
| /** | |||
| * swagger会解析的url规则 | |||
| **/ | |||
| private List<String> basePath = new ArrayList<>(); | |||
| /** | |||
| * 在basePath基础上需要排除的url规则 | |||
| **/ | |||
| private List<String> excludePath = new ArrayList<>(); | |||
| /** | |||
| * 标题 | |||
| **/ | |||
| private String title = ""; | |||
| /** | |||
| * 描述 | |||
| **/ | |||
| private String description = ""; | |||
| /** | |||
| * 版本 | |||
| **/ | |||
| private String version = ""; | |||
| /** | |||
| * 许可证 | |||
| **/ | |||
| private String license = ""; | |||
| /** | |||
| * 许可证URL | |||
| **/ | |||
| private String licenseUrl = ""; | |||
| /** | |||
| * 服务条款URL | |||
| **/ | |||
| private String termsOfServiceUrl = ""; | |||
| /** | |||
| * host信息 | |||
| **/ | |||
| private String host = ""; | |||
| /** | |||
| * 联系人信息 | |||
| */ | |||
| private Contact contact = new Contact(); | |||
| @Data | |||
| public static class Contact { | |||
| /** | |||
| * 联系人 | |||
| **/ | |||
| private String name = ""; | |||
| /** | |||
| * 联系人url | |||
| **/ | |||
| private String url = ""; | |||
| /** | |||
| * 联系人email | |||
| **/ | |||
| private String email = ""; | |||
| } | |||
| } | |||
| @@ -0,0 +1,5 @@ | |||
| package com.iformall.constant; | |||
| public interface SwaggerConstant { | |||
| String V_1_0_0 = "v1.0.0"; | |||
| } | |||
| @@ -18,6 +18,11 @@ | |||
| </properties> | |||
| <dependencies> | |||
| <dependency> | |||
| <groupId>com.iformall</groupId> | |||
| <artifactId>mallink-swagger</artifactId> | |||
| <version>1.0</version> | |||
| </dependency> | |||
| <dependency> | |||
| <groupId>com.iformall</groupId> | |||
| <artifactId>mallinkService</artifactId> | |||
| @@ -1,5 +1,6 @@ | |||
| package com.iformall; | |||
| import com.iformall.annotation.BaseEnableSwagger; | |||
| import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties; | |||
| import org.mybatis.spring.annotation.MapperScan; | |||
| import org.rocketmq.starter.annotation.EnableRocketMQ; | |||
| @@ -17,7 +18,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; | |||
| */ | |||
| @SpringBootApplication | |||
| @MapperScan(basePackages = {"com.iformall.mapper"}) | |||
| @EnableSwagger2 | |||
| @BaseEnableSwagger | |||
| @EnableEncryptableProperties | |||
| @EnableAsync | |||
| @EnableRocketMQ | |||
| @@ -134,11 +134,13 @@ public class ShiroConfig { | |||
| // filterChainDefinitionMap.put(resources.getUrl(),permission); | |||
| // } | |||
| // } | |||
| // swagger-ui | |||
| filterChainDefinitionMap.put("/swagger-ui.html", "anon"); | |||
| // swagger2 | |||
| filterChainDefinitionMap.put("/doc.html", "anon"); | |||
| filterChainDefinitionMap.put("/v2/**", "anon"); | |||
| filterChainDefinitionMap.put("/swagger-resources/**", "anon"); | |||
| filterChainDefinitionMap.put("/webjars/**", "anon"); | |||
| filterChainDefinitionMap.put("/B/**", "anon"); | |||
| filterChainDefinitionMap.put("/C/**", "anon"); | |||
| filterChainDefinitionMap.put("/version", "anon"); | |||
| filterChainDefinitionMap.put("/wxDeviceScreenAd/**", "anon"); | |||
| @@ -1,61 +1,61 @@ | |||
| package com.iformall.config; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.context.annotation.Bean; | |||
| import org.springframework.context.annotation.Configuration; | |||
| import springfox.documentation.builders.ApiInfoBuilder; | |||
| import springfox.documentation.builders.ParameterBuilder; | |||
| import springfox.documentation.builders.PathSelectors; | |||
| import springfox.documentation.builders.RequestHandlerSelectors; | |||
| import springfox.documentation.schema.ModelRef; | |||
| import springfox.documentation.service.ApiInfo; | |||
| import springfox.documentation.service.Parameter; | |||
| import springfox.documentation.spi.DocumentationType; | |||
| import springfox.documentation.spring.web.paths.RelativePathProvider; | |||
| import springfox.documentation.spring.web.plugins.Docket; | |||
| import springfox.documentation.swagger2.annotations.EnableSwagger2; | |||
| import javax.servlet.ServletContext; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| //参考:http://blog.csdn.net/catoop/article/details/50668896 | |||
| @Configuration | |||
| @EnableSwagger2 | |||
| public class Swagger2Config { | |||
| @Autowired | |||
| private ServletContext servletContext; | |||
| @Bean | |||
| public Docket createRestApi() { | |||
| ParameterBuilder tokenPar = new ParameterBuilder(); | |||
| List<Parameter> pars = new ArrayList<Parameter>(); | |||
| //增加一个request的header参数 | |||
| tokenPar.name("token").description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build(); | |||
| pars.add(tokenPar.build()); | |||
| return new Docket(DocumentationType.SWAGGER_2) | |||
| .apiInfo(apiInfo()) | |||
| .select() | |||
| .apis(RequestHandlerSelectors.basePackage("com.iformall.controller")) | |||
| .paths(PathSelectors.any()) | |||
| .build() | |||
| .globalOperationParameters(pars) | |||
| .pathProvider(new RelativePathProvider(servletContext) { | |||
| @Override | |||
| public String getApplicationBasePath() { | |||
| return "/api"; | |||
| } | |||
| }); | |||
| } | |||
| private ApiInfo apiInfo() { | |||
| return new ApiInfoBuilder() | |||
| .title("a端 api") | |||
| .description("a api") | |||
| .termsOfServiceUrl("http://localhost:7000") | |||
| .version("2.0") | |||
| .build(); | |||
| } | |||
| } | |||
| //package com.iformall.config; | |||
| // | |||
| //import org.springframework.beans.factory.annotation.Autowired; | |||
| //import org.springframework.context.annotation.Bean; | |||
| //import org.springframework.context.annotation.Configuration; | |||
| //import springfox.documentation.builders.ApiInfoBuilder; | |||
| //import springfox.documentation.builders.ParameterBuilder; | |||
| //import springfox.documentation.builders.PathSelectors; | |||
| //import springfox.documentation.builders.RequestHandlerSelectors; | |||
| //import springfox.documentation.schema.ModelRef; | |||
| //import springfox.documentation.service.ApiInfo; | |||
| //import springfox.documentation.service.Parameter; | |||
| //import springfox.documentation.spi.DocumentationType; | |||
| //import springfox.documentation.spring.web.paths.RelativePathProvider; | |||
| //import springfox.documentation.spring.web.plugins.Docket; | |||
| //import springfox.documentation.swagger2.annotations.EnableSwagger2; | |||
| // | |||
| //import javax.servlet.ServletContext; | |||
| //import java.util.ArrayList; | |||
| //import java.util.List; | |||
| // | |||
| ////参考:http://blog.csdn.net/catoop/article/details/50668896 | |||
| //@Configuration | |||
| //@EnableSwagger2 | |||
| //public class Swagger2Config { | |||
| // | |||
| // @Autowired | |||
| // private ServletContext servletContext; | |||
| // | |||
| // @Bean | |||
| // public Docket createRestApi() { | |||
| // ParameterBuilder tokenPar = new ParameterBuilder(); | |||
| // List<Parameter> pars = new ArrayList<Parameter>(); | |||
| // //增加一个request的header参数 | |||
| // tokenPar.name("token").description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build(); | |||
| // pars.add(tokenPar.build()); | |||
| // return new Docket(DocumentationType.SWAGGER_2) | |||
| // .apiInfo(apiInfo()) | |||
| // .select() | |||
| // .apis(RequestHandlerSelectors.basePackage("com.iformall.controller")) | |||
| // .paths(PathSelectors.any()) | |||
| // .build() | |||
| // .globalOperationParameters(pars) | |||
| // .pathProvider(new RelativePathProvider(servletContext) { | |||
| // @Override | |||
| // public String getApplicationBasePath() { | |||
| // return "/api"; | |||
| // } | |||
| // }); | |||
| // } | |||
| // | |||
| // private ApiInfo apiInfo() { | |||
| // return new ApiInfoBuilder() | |||
| // .title("a端 api") | |||
| // .description("a api") | |||
| // .termsOfServiceUrl("http://localhost:7000") | |||
| // .version("2.0") | |||
| // .build(); | |||
| // } | |||
| // | |||
| //} | |||
| @@ -100,7 +100,7 @@ public class WebConfig implements WebMvcConfigurer { | |||
| @Override | |||
| public void addResourceHandlers(ResourceHandlerRegistry registry) { | |||
| registry.addResourceHandler("swagger-ui.html") | |||
| registry.addResourceHandler("/doc.html") | |||
| .addResourceLocations("classpath:/META-INF/resources/"); | |||
| registry.addResourceHandler("/webjars/**") | |||
| .addResourceLocations("classpath:/META-INF/resources/webjars/"); | |||
| @@ -2,10 +2,12 @@ package com.iformall.controller.sys; | |||
| import com.google.code.kaptcha.Constants; | |||
| import com.google.code.kaptcha.Producer; | |||
| import com.iformall.annotation.ApiVersion; | |||
| import com.iformall.annotation.SystemControllerLog; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.constant.SwaggerConstant; | |||
| import com.iformall.controller.base.BaseController; | |||
| import com.iformall.domain.po.MallUserInfo; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| @@ -92,6 +94,7 @@ public class HomeController extends BaseController { | |||
| @Qualifier("objectCommonRedisTemplate") | |||
| RedisTemplate<String, Object> redisTemplate; | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation("验证码") | |||
| @GetMapping("/captcha.jpg") | |||
| public void captcha(HttpServletResponse response)throws ServletException, IOException { | |||
| @@ -201,4 +201,23 @@ ueditor: | |||
| logging: | |||
| level: | |||
| com.iformall: debug | |||
| path: ./logs/admin | |||
| path: ./logs/admin | |||
| debug: true | |||
| swagger: | |||
| services: | |||
| a: / | |||
| b: /B | |||
| pre-path: ${server.servlet.context-path} | |||
| base-package: com.iformall.controller | |||
| title: 富茂_iformall_接口文档 | |||
| description: 前后端联调 | |||
| version: 1.0 | |||
| license: Apache | |||
| license-url: https://admintest.malls.iformall.com | |||
| terms-of-service-url: https://admintest.malls.iformall.com | |||
| host: https://admintest.malls.iformall.com | |||
| contact: | |||
| name: 张三 | |||
| url: https://admintest.malls.iformall.com | |||
| email: zhangsan@163.com | |||
| @@ -12,6 +12,11 @@ | |||
| <artifactId>mallinkBApi</artifactId> | |||
| <dependencies> | |||
| <dependency> | |||
| <groupId>com.iformall</groupId> | |||
| <artifactId>mallink-swagger</artifactId> | |||
| <version>1.0</version> | |||
| </dependency> | |||
| <dependency> | |||
| <groupId>com.iformall</groupId> | |||
| <artifactId>mallinkService</artifactId> | |||
| @@ -1,5 +1,6 @@ | |||
| package com.iformall; | |||
| import com.iformall.annotation.BaseEnableSwagger; | |||
| import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties; | |||
| import org.mybatis.spring.annotation.MapperScan; | |||
| import org.rocketmq.starter.annotation.EnableRocketMQ; | |||
| @@ -13,6 +14,7 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy; | |||
| * @author chenkx | |||
| * @date 2017-12-26 | |||
| */ | |||
| @BaseEnableSwagger | |||
| @SpringBootApplication | |||
| @MapperScan(basePackages = {"com.iformall.mapper"}) | |||
| @EnableEncryptableProperties | |||
| @@ -1,49 +1,49 @@ | |||
| package com.iformall.config; | |||
| import org.springframework.context.annotation.Bean; | |||
| import org.springframework.context.annotation.Configuration; | |||
| import springfox.documentation.builders.ApiInfoBuilder; | |||
| import springfox.documentation.builders.ParameterBuilder; | |||
| import springfox.documentation.builders.PathSelectors; | |||
| import springfox.documentation.builders.RequestHandlerSelectors; | |||
| import springfox.documentation.schema.ModelRef; | |||
| import springfox.documentation.service.ApiInfo; | |||
| import springfox.documentation.service.Parameter; | |||
| import springfox.documentation.spi.DocumentationType; | |||
| import springfox.documentation.spring.web.plugins.Docket; | |||
| import springfox.documentation.swagger2.annotations.EnableSwagger2; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| //参考:http://blog.csdn.net/catoop/article/details/50668896 | |||
| @Configuration | |||
| @EnableSwagger2 | |||
| public class Swagger2Config { | |||
| @Bean | |||
| public Docket createRestApi() { | |||
| ParameterBuilder tokenPar = new ParameterBuilder(); | |||
| List<Parameter> pars = new ArrayList<Parameter>(); | |||
| //增加一个request的header参数 | |||
| tokenPar.name("token").description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build(); | |||
| pars.add(tokenPar.build()); | |||
| return new Docket(DocumentationType.SWAGGER_2) | |||
| .apiInfo(apiInfo()) | |||
| .select() | |||
| .apis(RequestHandlerSelectors.basePackage("com.iformall.controller")) | |||
| .paths(PathSelectors.any()) | |||
| .build() | |||
| .globalOperationParameters(pars); | |||
| } | |||
| private ApiInfo apiInfo() { | |||
| return new ApiInfoBuilder() | |||
| .title("b端 api") | |||
| .description("b端 api") | |||
| .termsOfServiceUrl("http://localhost:8000") | |||
| .version("2.0") | |||
| .build(); | |||
| } | |||
| } | |||
| //package com.iformall.config; | |||
| // | |||
| //import org.springframework.context.annotation.Bean; | |||
| //import org.springframework.context.annotation.Configuration; | |||
| //import springfox.documentation.builders.ApiInfoBuilder; | |||
| //import springfox.documentation.builders.ParameterBuilder; | |||
| //import springfox.documentation.builders.PathSelectors; | |||
| //import springfox.documentation.builders.RequestHandlerSelectors; | |||
| //import springfox.documentation.schema.ModelRef; | |||
| //import springfox.documentation.service.ApiInfo; | |||
| //import springfox.documentation.service.Parameter; | |||
| //import springfox.documentation.spi.DocumentationType; | |||
| //import springfox.documentation.spring.web.plugins.Docket; | |||
| //import springfox.documentation.swagger2.annotations.EnableSwagger2; | |||
| // | |||
| //import java.util.ArrayList; | |||
| //import java.util.List; | |||
| // | |||
| ////参考:http://blog.csdn.net/catoop/article/details/50668896 | |||
| //@Configuration | |||
| //@EnableSwagger2 | |||
| //public class Swagger2Config { | |||
| // | |||
| // @Bean | |||
| // public Docket createRestApi() { | |||
| // ParameterBuilder tokenPar = new ParameterBuilder(); | |||
| // List<Parameter> pars = new ArrayList<Parameter>(); | |||
| // //增加一个request的header参数 | |||
| // tokenPar.name("token").description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build(); | |||
| // pars.add(tokenPar.build()); | |||
| // return new Docket(DocumentationType.SWAGGER_2) | |||
| // .apiInfo(apiInfo()) | |||
| // .select() | |||
| // .apis(RequestHandlerSelectors.basePackage("com.iformall.controller")) | |||
| // .paths(PathSelectors.any()) | |||
| // .build() | |||
| // .globalOperationParameters(pars); | |||
| // } | |||
| // | |||
| // private ApiInfo apiInfo() { | |||
| // return new ApiInfoBuilder() | |||
| // .title("b端 api") | |||
| // .description("b端 api") | |||
| // .termsOfServiceUrl("http://localhost:8000") | |||
| // .version("2.0") | |||
| // .build(); | |||
| // } | |||
| // | |||
| //} | |||
| @@ -45,7 +45,7 @@ public class WebMvcConfig implements WebMvcConfigurer { | |||
| @Override | |||
| public void addResourceHandlers(ResourceHandlerRegistry registry) { | |||
| registry.addResourceHandler("swagger-ui.html") | |||
| registry.addResourceHandler("/doc.html") | |||
| .addResourceLocations("classpath:/META-INF/resources/"); | |||
| registry.addResourceHandler("/webjars/**") | |||
| .addResourceLocations("classpath:/META-INF/resources/webjars/"); | |||
| @@ -1,7 +1,9 @@ | |||
| package com.iformall.controller; | |||
| import com.iformall.annotation.ApiVersion; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.constant.SwaggerConstant; | |||
| import com.iformall.enums.EnumSharingReceiverAccountType; | |||
| import com.iformall.service.bank.WxBankUtilService; | |||
| import io.swagger.annotations.Api; | |||
| @@ -26,6 +28,7 @@ public class BankController extends BaseController{ | |||
| @Autowired | |||
| private WxBankUtilService wxBankUtilService; | |||
| @ApiVersion(group = SwaggerConstant.V_1_0_0) | |||
| @ApiOperation("根据对私银行卡号获取开户银行") | |||
| @GetMapping("/searchBanks") | |||
| public ResultData searchBanks(String accountNumber) { | |||
| @@ -187,4 +187,19 @@ pos: | |||
| logging: | |||
| level: | |||
| com.iformall.mapper: debug | |||
| path: ./logs/b | |||
| path: ./logs/b | |||
| swagger: | |||
| pre-path: ${server.servlet.context-path} | |||
| base-package: com.iformall.controller | |||
| title: 富茂_iformall_接口文档 | |||
| description: 前后端联调 | |||
| version: 1.0 | |||
| license: Apache | |||
| license-url: https://admintest.malls.iformall.com | |||
| terms-of-service-url: https://admintest.malls.iformall.com | |||
| host: https://admintest.malls.iformall.com | |||
| contact: | |||
| name: 张三 | |||
| url: https://admintest.malls.iformall.com | |||
| email: zhangsan@163.com | |||
| @@ -27,6 +27,7 @@ | |||
| <module>mallinkTTCApi</module> | |||
| <module>mallinkTTAdmin</module> | |||
| <module>mallinkNeuPosAdmin</module> | |||
| <module>mallink-swagger</module> | |||
| </modules> | |||
| <parent> | |||