diff --git a/src/demo/pom.xml b/src/demo/pom.xml index 8e096ca..06fb0c9 100644 --- a/src/demo/pom.xml +++ b/src/demo/pom.xml @@ -82,18 +82,27 @@ mybatis-plus-boot-starter 3.1.1 - + - io.springfox - springfox-swagger2 - 2.9.2 + org.springdoc + springdoc-openapi-ui + 1.6.6 - com.github.xiaoymin - swagger-bootstrap-ui - 1.9.2 + org.springdoc + springdoc-openapi-common + 1.6.6 + + + io.swagger.core.v3 + swagger-models + 2.1.12 + + + io.swagger.core.v3 + swagger-annotations + 2.1.12 - diff --git a/src/demo/src/main/java/com/example/demo/DemoApplication.java b/src/demo/src/main/java/com/example/demo/DemoApplication.java index fa90a14..da345d0 100644 --- a/src/demo/src/main/java/com/example/demo/DemoApplication.java +++ b/src/demo/src/main/java/com/example/demo/DemoApplication.java @@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; @SpringBootApplication -@ComponentScan("com.example.demo.controller") +@ComponentScan(basePackages = {"com.example.demo.controller" ,"com.example.demo.config"}) @MapperScan("com.example.demo.mapper") public class DemoApplication { diff --git a/src/demo/src/main/java/com/example/demo/config/SpringDocConfig.java b/src/demo/src/main/java/com/example/demo/config/SpringDocConfig.java new file mode 100644 index 0000000..b944b06 --- /dev/null +++ b/src/demo/src/main/java/com/example/demo/config/SpringDocConfig.java @@ -0,0 +1,27 @@ +package com.example.demo.config; + +import io.swagger.v3.oas.models.ExternalDocumentation; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.info.License; +import org.springdoc.core.GroupedOpenApi; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * SpringDoc API文档相关配置 + * Created by macro on 2022/3/4. + */ +@Configuration +public class SpringDocConfig { + + + @Bean + public GroupedOpenApi publicApi() { + return GroupedOpenApi.builder() + .group("") + .pathsToMatch("") + .build(); + } +} + diff --git a/src/demo/src/main/java/com/example/demo/config/SwaggerConfig.java b/src/demo/src/main/java/com/example/demo/config/SwaggerConfig.java deleted file mode 100644 index de2eec6..0000000 --- a/src/demo/src/main/java/com/example/demo/config/SwaggerConfig.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.example.demo.config; -import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI; - -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.spi.DocumentationType; -import springfox.documentation.spring.web.plugins.Docket; -import springfox.documentation.swagger2.annotations.EnableSwagger2; - - -/** - * @author lyr - */ - -@Profile({"prd","test","dev"}) -@Configuration -@EnableSwagger2 -@EnableSwaggerBootstrapUI -public class SwaggerConfig { - - @Bean - public Docket api() { -// List globalRequestParameters = new ArrayList<>(); -// RequestParameter build = new RequestParameterBuilder().name("abc").description("添加swagger公共请求参数abc").required(true).build(); - return new Docket(DocumentationType.SWAGGER_2) - .select() - .apis(RequestHandlerSelectors.basePackage("com.qkc.stat.controller")) - .paths(PathSelectors.any()) - .build() -// .globalRequestParameters(globalRequestParameters) -// .securitySchemes(securitySchemes()) //添加token -// .securityContexts(securityContexts()) //swagger配置页面访问是否需要传token - .apiInfo(apiInfo()); - } - - private ApiInfo apiInfo() { - return new ApiInfoBuilder() - .title("统计信息服务") - .description("统计服务相关接口") - .termsOfServiceUrl("127.0.0.1") - .version("1.0.0") - .build(); - } - - -} \ No newline at end of file diff --git a/src/demo/src/main/java/com/example/demo/config/WebMvnConfig.java b/src/demo/src/main/java/com/example/demo/config/WebMvnConfig.java deleted file mode 100644 index a8042b5..0000000 --- a/src/demo/src/main/java/com/example/demo/config/WebMvnConfig.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.example.demo.config; - -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.CorsRegistry; -import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; - -/** - * @Author: lyr - * @Date: 2021-04-21 10:13 - */ -@Configuration -public class WebMvnConfig extends WebMvcConfigurationSupport { - - @Override - public void addCorsMappings(CorsRegistry registry) { - - registry.addMapping("/**") - .allowedOrigins("*") - .allowedMethods("PUT", "DELETE", "GET", "POST", "OPTIONS") - .allowCredentials(true).maxAge(3600); - - } - - @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/"); - registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); - } - -} diff --git a/src/demo/src/main/java/com/example/demo/controller/ControllerText.java b/src/demo/src/main/java/com/example/demo/controller/ControllerText.java index b70f175..06ab518 100644 --- a/src/demo/src/main/java/com/example/demo/controller/ControllerText.java +++ b/src/demo/src/main/java/com/example/demo/controller/ControllerText.java @@ -1,5 +1,9 @@ package com.example.demo.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.tags.Tags; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -14,9 +18,11 @@ import java.util.Map; @RestController @SpringBootApplication +@Tag(name ="你的接口",description = "test") public class ControllerText { - + @Operation(summary = "获取用户列表",description = "test") @RequestMapping("getUser") + public Map getUser(){ System.out.println("微信小程序正在调用。。。"); Map map = new HashMap(); @@ -29,7 +35,7 @@ public class ControllerText { System.out.println("微信小程序调用完成。。。"); return map; } - + @Operation(summary = "获取用户表",description = "test") @RequestMapping("getWord") public Map getText(String word){ Map map = new HashMap(); @@ -44,7 +50,7 @@ public class ControllerText { map.put("message", message); return map; } - + @Operation(summary = "获取列表",description = "test") @RequestMapping("") public String getText(){ return "hello world"; @@ -52,6 +58,7 @@ public class ControllerText { @Autowired JdbcTemplate jct; + @Operation(summary = "取用户列表",description = "test") @GetMapping("userslist") public List> userlist(){ String sql = "select * from user";