1.引入依赖
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.swagger.core.v3/swagger-annotations -->
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.1.10</version>
</dependency>
- 配置文件
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Order(40)
@Configuration
@EnableSwagger2
@ComponentScan("com.yhr.jixiao.admin.controller")
//@Profile({"dev","test"})
//@ConditionalOnProperty(name = "swagger.enable", havingValue = "true")
public class Swagger2Config {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(new ApiInfoBuilder()
.title("阅文HR_绩效管理后台_接口文档")
.description("绩效管理后台")
.contact(new Contact("yhr", null, "xxx@163.com"))
.version("版本号:1.0")
.build())
.enable(true)
.select()
// .apis(RequestHandlerSelectors.basePackage("com.yhr.menu.controller"))
// .paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("阅文HR_绩效管理后台_接口文档")
.description("绩效管理后台")
.contact(new Contact("yhr", "url", "xxx@163.com"))
.version("1.0")
.build();
}
}
- 1)controller 注解
@Api(value = "菜单数据Controller", tags = { "菜单" })`
2)method 注解
@ApiOperation(value = "初始化所有在职人员的菜单信息", notes = "计算所有人员的菜单显示权限,缓存到Redis,提升效率", httpMethod = "GET")`
3)参数注解
@ApiParam(name="appcode",value="应用clientid",required=true) @RequestParam("appcode")String appcode, @ApiParam(name="badge",value="员工工号",required=true)@RequestParam("badge")String badge`