標籤:bubuko hand index expected rest 掃描 exp control 作者
博主很懶...
Swagger官網:http://swagger.io
GitHub地址:https://github.com/swagger-api
官方註解文檔:http://docs.swagger.io/swagger-core/apidocs/index.html
Swagger-UI地址:https://github.com/swagger-api/swagger-ui
swagger最終
好,開始說Spring怎麼配置Swagger了1.pom.xml引入需要的jar包
<!-- 構建Restful API 我這版本是2.6.1 --><dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>${swagger2.version}</version></dependency><dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>${swagger2.version}</version></dependency>2.掃描你的Swagger2config.java所在的包
<!-- url是你需要掃描swagger的包路徑 --><context:component-scan base-package="com.nickwilde.microtrain.common.config.swagger"/>
3.Swagger2config.java[類名自訂]
package com.nickwilde.microtrain.common.config.swagger2;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.ApiInfo;import springfox.documentation.service.Contact;import springfox.documentation.spi.DocumentationType;import springfox.documentation.spring.web.plugins.Docket;import springfox.documentation.swagger2.annotations.EnableSwagger2;/** * @author NickWilde * @version 2018/1/18 10:23 * @description: Swagger2Config * TODO 用一句話描述 */@Configuration@EnableSwagger2public class Swagger2Config{ @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2).forCodeGeneration(true) .select() .apis(RequestHandlerSelectors.any()) //過濾產生連結 .paths(PathSelectors.any()) .build() .apiInfo(apiInfo()); } //api介面作者相關資訊 private ApiInfo apiInfo() { Contact contact = new Contact("NickWilde", "", "[email protected]"); ApiInfo apiInfo = new ApiInfoBuilder() .license("Apache License Version 2.0") .title("Unexpectedly系統") .description("介面文檔") .contact(contact) .version("1.0") .build(); return apiInfo; }}4.給你的controller加上額外註解(不加也是有的)
@ApiOperation(value="根據User對象建立使用者", notes="根據User對象建立使用者",httpMethod = "POST") //httpMehtod如果不定義,那麼swagger會有把該介面的所有要求方法都一一列舉出來@ApiImplicitParam(name = "data", value = "data描述", required = true, dataType = "UserInfo") //參數定義..類型..之類的,這是基礎簡單,其餘的看api吧~
Spring整合Swagger,Java自動產生Api文檔