赞
踩
SpringDoc也是 spring 社区维护的一个项目(非官方),帮助使用者将 swagger3 集成到 Spring 中。
也是用来在 Spring 中帮助开发者生成文档,并可以轻松的在spring boot中使用。
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>3.1.0</version>
- <relativePath/> <!-- lookup parent from repository -->
- </parent>
-
- <dependency>
- <groupId>org.springdoc</groupId>
- <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
- <version>2.0.4</version>
- </dependency>
- @Configuration
- public class OpenApiConfig {
-
-
- @Bean
- public OpenAPI mallTinyOpenAPI() {
- return new OpenAPI()
- .info(
- new Info().title("SpringDoc API")
- .description("SpringDoc API 演示")
- .version("v1.0.0")
- .license(new License().name("Apache 2.0")))
- .externalDocs(new ExternalDocumentation()
- .description("SpringBoot项目全套文档"));
- }
-
-
- @Bean
- public GroupedOpenApi account() {
- return GroupedOpenApi.builder()
- .group("A-User")
- .displayName("A-User System")
- .pathsToMatch("/api/**/SysUser/**")
- .build();
- }
-
- @Bean
- public GroupedOpenApi publicApi() {
- return GroupedOpenApi.builder()
- .group("brand")
- .pathsToMatch("/api/**/message/**")
- .build();
- }
-
- }
- @RestController
- @RequestMapping(value = "/api/{channel}/{version}/SysUser")
- public interface UserSystemServer {
-
- @PostMapping(value = "/code")
- @Operation(summary = "管理员#发送验证码", description = "发送验证码", tags = {"Code Management"})
- @Parameters(value = {
- @Parameter(name = "version", description = "协议版本", example = "v1"),
- @Parameter(name = "channel", description = "渠道", example = "web")
- })
- Result code(@PathVariable String channel,@PathVariable String version, @RequestBody Map<String, Object> account);
-
- @ResponseBody
- @PostMapping(value = "/add/user")
- @Operation(summary = "新增用户", description = "新增用户", tags = {"User Management"})
- @Parameters(value = {
- @Parameter(name = "version", description = "协议版本", example = "v1"),
- @Parameter(name = "channel", description = "渠道", example = "web")
- })
- Result addUser(@PathVariable String channel,@PathVariable String version, String name);
-
- @ResponseBody
- @PostMapping(value = "/del/user")
- @Operation(summary = "删除用户", description = "删除用户", tags = {"User Management"})
- @Parameters(value = {
- @Parameter(name = "version", description = "协议版本", example = "v1"),
- @Parameter(name = "channel", description = "渠道", example = "web")
- })
- Result delUser(@PathVariable String channel,@PathVariable String version, String name);
-
-
- @ResponseBody
- @PostMapping(value = "/update/user")
- @Operation(summary = "编辑用户", description = "编辑用户", tags = {"User Management"})
- @Parameters(value = {
- @Parameter(name = "version", description = "协议版本", example = "v1"),
- @Parameter(name = "channel", description = "渠道", example = "web")
- })
- Result updateUser(@PathVariable String channel,@PathVariable String version, @RequestBody Map<String, Object> account);
- }
- @RestController
- public class SysUserController implements UserSystemServer {
-
-
- @Override
- public Result code(String channel, String version, Map<String, Object> account) {
- return Result.ok().success("test");
- }
-
- @Override
- public Result addUser(String channel, String version, String name) {
- return Result.ok().success("test");
- }
-
- @Override
- public Result delUser(String channel, String version, String name) {
- return Result.ok().success("test");
- }
-
- @Override
- public Result updateUser(String channel, String version, Map<String, Object> account) {
- return Result.ok().success("test");
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。