步驟:
一、添加依賴
<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 傳參,就是實際的值