导入maven的swagger包
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>
configure配置
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket docket(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.xx"))
.paths(PathSelectors.any())
.build().pathMapping("/");
}
public ApiInfo apiInfo(){
Contact contact=new Contact("zhangSang","http://www.abc.com","123456@qq.com");
return new ApiInfoBuilder()
.title("API文档")
.description("talk is cheap , show me the code~")
.termsOfServiceUrl("")
.version("1.0")
.build();
}
}
配置完成之后,重启项目,输入http://localhost:8080/swagger-ui.html即可进入swagger文档页面.
controller层 ,方法添加说明
@Api(tags = "接口")
方法上的说明
@ApiOperation(value = "添加用户", notes = "根据用户名,密码添加用户")