首先需要導(dǎo)入Swagger依賴
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.4.0</version> </dependency>
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.4.0</version> </dependency>
在使用Swagger的Controller中使用注解
@EnableSwagger2
定義Swagger的Bean
@Bean
public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.basePackage("com.elong.Controller")) .paths(PathSelectors.ant("/api/*")) .build().apiInfo(apiInfo()); }
private ApiInfo apiInfo() { ApiInfo apiInfo = new ApiInfo( "Autops REST API", "Autops平臺接口", "API TOS", "OPS", "xianghui.niu", "License of API", ""); return apiInfo; }
- 主要的注解使用方法
- @Api : 注解Controller痢甘,對應(yīng)UI中一組API 的命名 description: 描述信息, tag: 標(biāo)簽
- @ApiOperation value: api的功能介紹
- @ApiImplicitParam(name = "id", value = "執(zhí)行單號", paramType = "query")
- @ApiResponses(value = {@ApiResponse(code = 200, message = "接口調(diào)用成功")})