首先在pom中导入相应的依赖文件
建立config文件SwaggerConfig.java
package com.mansh.vschool.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket createRestApi(){
return new Docket(DocumentationType.SWAGGER_2)
.pathMapping("/")
.select()
.apis(RequestHandlerSelectors.basePackage("com.mansh.vschool"))
.paths(PathSelectors.any())
.build().apiInfo(new ApiInfoBuilder()
.title("测试系统接口详细信息")
.version("1.0")
.contact(new Contact("man","https://mail.163.com/","mansh0427@163.com"))
.license("The Apache License")
.licenseUrl("http://www.baidu.com")
.build());
}
}
在写Controller的方法的时候,使用相关的注解
项目启动后,可以到http://{IP}{port}{项目}/doc,html,查看注释生成的接口文档
接触时间不长,如果有其他的更好用的接口管理工具,或者有更好的使用方法,欢迎讨论