<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency> @Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.basePackage("com.example.api")) .paths(PathSelectors.any()) .build() .apiInfo(apiInfo()) .groupName("v1.0"); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .version("1.0") .build(); } } @RestController @RequestMapping("/api") public class ApiController { @ApiVersion("1.0") @ApiImplicitParams({ }) @GetMapping("/user/{userId}") public User getUser(@PathVariable Long userId) { } @ApiVersion("2.0") @ApiImplicitParams({ }) @GetMapping("/user/{username}") public User getUser(@PathVariable String username) { } }


上一篇:
下一篇:
切换中文