步骤:
一、添加依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.3</version>
</dependency>
二、添加配置类
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
@Bean
public Docket restApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.paths(PathSelectors.any())
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("")
.version("1.0")
.build();
}
}
三、添加注解
controller的class上@Api(tags = “test”, produces = “test”)
方法上:@ApiOperation(“xx”)
实体类属性上添加@ApiModelProperty(value = “用户的ID”, required = false)
四、访问地址
http://localhost:8080/doc.html
五、注意事项
参数为对象用@Valid,显示更友好@RequestBody显示为json格式,自己试一下就晓得了
@ApiParam 传参,只是显示作用
@requestParam 传参,就是实际的值