1.了解到 https://swagger.io/tools/swaggerhub
2.swagger2引入pom文件
<!--引入Swagger --> <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>
3.创建Swagger配置类
public Docket xxxxapi(){ return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()).select() .apis(RequestHandlerSelectors.basePackage("com.xxxx.xxxx.controller")) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("xxxx") .version("x.x") .build(); }
3.Swagger中注解的说明
@Api 标注在类上面
@ApiOperation 标注在方法上
@ApiImplicitParam 请求参数的,字段,名称,是否必填,传送方式。
@ApiModel 返回参数的一个描述
@ApiModelProperty 返回对象的字段描述