Use swagger2 generate documentation

1. Add dependency in pom.xml

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

2. Create the configuration of class SwaggerConfig Swagger2

@Configuration   // This is a configuration class 
@ EnableSwagger2 // open document 
public  class SwaggerConfig {
     // attribute 1. Declare api documentation, builder 
    Private ApiInfo apiInfo () {
         return  new new ApiInfoBuilder (). Title ( "use SpringBoot online document building RestFul style Apis " )
                .description("gxh").contact("gxh").version("1.0").build();
    }

    // 2. Configuration core configuration information 
    public Docket No. createRestApi () {
         return  new new Docket No. (DocumentationType.SWAGGER_2)
                .apiInfo (apiInfo ())
                .select().apis(RequestHandlerSelectors.basePackage("com.offcn.springbootdemo.controller"))
                .paths(PathSelectors.any()).build();
    }
}

3. Add documentation comments on the Controller under the category Controller package

  By @ApiOperation annotation to add a description to the API;

  By @ ApiImplicitParams, @ ApiImplicitParam annotation to add a description to the parameter;

 

4. Run to view documents generated Swagger2

Once started, enter in your browser: http: // localhost: 8080 / swagger-ui.html

 

 

Guess you like

Origin www.cnblogs.com/gxh494/p/11802292.html