From dc31792dc1b8ad1658e49ba8fce9a1be924e6fbb Mon Sep 17 00:00:00 2001 From: wu <731351411@qq.com> Date: 星期四, 30 十一月 2023 08:44:04 +0800 Subject: [PATCH] 理片笼测试修改 --- springboot-vue3/src/main/java/com/example/springboot/config/SwaggerConfig.java | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 59 insertions(+), 0 deletions(-) diff --git a/springboot-vue3/src/main/java/com/example/springboot/config/SwaggerConfig.java b/springboot-vue3/src/main/java/com/example/springboot/config/SwaggerConfig.java new file mode 100644 index 0000000..1166481 --- /dev/null +++ b/springboot-vue3/src/main/java/com/example/springboot/config/SwaggerConfig.java @@ -0,0 +1,59 @@ +package com.example.springboot.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +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.EnableSwagger2; + +/** + * swagger閰嶇疆 + * 椤圭洰杩愯鍚庤闂細http://localhost:port/swagger-ui.html + */ +@Configuration +@EnableSwagger2 +public class SwaggerConfig { + // 閰嶇疆swagger2鏍稿績閰嶇疆 docket + @Bean + public Docket createRestApi() { + return new Docket(DocumentationType.SWAGGER_2) // 鎸囧畾api绫诲瀷涓簊wagger2 + .groupName("authority") // 鍒嗙粍 + .apiInfo(apiInfo()) // 鐢ㄤ簬瀹氫箟api鏂囨。姹囨�讳俊鎭� + .select() // 閫氳繃.select()鏂规硶锛屽幓閰嶇疆鎵弿鎺ュ彛銆俁equestHandlerSelectors閰嶇疆濡備綍鎵弿鎺ュ彛 + /* + // RequestHandlerSelectors閰嶇疆鏂规硶 + any() // 鎵弿鎵�鏈夛紝椤圭洰涓殑鎵�鏈夋帴鍙i兘浼氳鎵弿鍒� + none() // 涓嶆壂鎻忔帴鍙� + // 閫氳繃鏂规硶涓婄殑娉ㄨВ鎵弿锛屽withMethodAnnotation(GetMapping.class)鍙壂鎻廹et璇锋眰 + withMethodAnnotation( final Class<? extends Annotation> annotation) + // 閫氳繃绫讳笂鐨勬敞瑙f壂鎻忥紝濡�.withClassAnnotation(Controller.class)鍙壂鎻忔湁controller娉ㄨВ鐨勭被涓殑鎺ュ彛 + withClassAnnotation( final Class<? extends Annotation> annotation) + basePackage( final String basePackage) // 鏍规嵁鍖呰矾寰勬壂鎻忔帴鍙� + */ + .apis(RequestHandlerSelectors.basePackage("com.canadames")) // 鎸囧畾鎵弿鍖� + /* + // 閰嶇疆濡備綍閫氳繃path杩囨护,鍗宠繖閲屽彧鎵弿璇锋眰浠�/寮�澶寸殑鎺ュ彛 + any() // 浠讳綍璇锋眰閮芥壂鎻� + none() // 浠讳綍璇锋眰閮戒笉鎵弿 + regex(final String pathRegex) // 閫氳繃姝e垯琛ㄨ揪寮忔帶鍒� + ant(final String antPattern) // 閫氳繃ant()鎺у埗 + */ + .paths(PathSelectors.any()) // 鎵�鏈塩ontroller + .build(); + } + + //鏋勫缓 api鏂囨。鐨勮缁嗕俊鎭嚱鏁�,娉ㄦ剰杩欓噷鐨勬敞瑙e紩鐢ㄧ殑鏄摢涓� + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("鏉冮檺绠$悊绯荤粺 API") // 鏂囨。椤垫爣棰� + .contact(new Contact("canadames", "https://jonssonyan.com", "yz808@outlook.com")) // 鑱旂郴浜轰俊鎭� + .version("1.0") // 鏂囨。鐗堟湰鍙� + .description("API 鎻忚堪") // 鎻忚堪 + .build(); + } +} -- Gitblit v1.8.0