Springboot添加Swagger

springboot添加swagger步驟:

1:在Pom中添加包依賴

<!-- swagger -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.8.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.8.0</version>
        </dependency>

2:添加swagger的配置

@Configuration
@EnableSwagger2
public class Swagger2Configurer {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
                .apis(Predicates.and(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class), RequestHandlerSelectors.basePackage("com.teligen.dazt.controller")))
                .paths(PathSelectors.any()).build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("RESTful接口").description("RESTful接口").version("1.1.0").build();
    }
}

3:在controller中添加對應的註解

Controller中添加

controller類:

@Api(tags = "個人基本信息接口")

controller方法:

@ApiOperation("獲取個人基礎信息")
@ApiImplicitParams({
        @ApiImplicitParam(name = "dabh", value = "檔案編號", required = true, dataType = "String")
})

model實體:

@ApiModel(value = "人員基礎信息實體",description = "")

實體類屬性

@ApiModelProperty(value = "數據來源",example = "人員基礎信息")
發佈了42 篇原創文章 · 獲贊 5 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章