springboot swagger Configuration

 

meven arrangement

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

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

springboot scan

/ ** 
 * Swagger2 interface configuration * / 
@Configuration 
@ EnableSwagger2 
public  class SwaggerConfig {
     / ** 
     * Creating API 
     * / 
    @Bean 
    public Docket createRestApi () {
         return  new new Docket (DocumentationType.SWAGGER_2)
                 // Details customization 
                .apiInfo (apiInfo ()) 
                .Select () 
                // specify the current packet path 
                .apis (RequestHandlerSelectors.basePackage ( "com.xiao.tool" ))
                 // scan all .apis (RequestHandlerSelectors.any ()) 
                 .paths (PathSelectors.any () )
                .build (); 
    } 

    / * * 
     * add summary information 
     * / 
    Private ApiInfo apiInfo () {
         // customized with ApiInfoBuilder 
        return  new new ApiInfoBuilder () 
                .title ( "Title: Document Interface" ) 
                .description ( "Description: interface document " ) 
                .contact ( new new Business Card (" Tool ", null , null )) 
                .version ( " version: 1.0 " ) 
                .build (); 
    } 
}

use

@RestController
@RequestMapping("/test")
@Api(description = "test")
public class TestController {


    @PostMapping("/test")
    @ApiOperation("test")
    public ApiResult test(Map map) throws Exception {
        return ApiResult.success("ok");
    }
}
Main comment 
@Api (description = "test") acts on the Controller class
@ApiOperation ( "test") acts on the method
@ApiModel acting on the entity class
@ApiModelProperty acting on the entity properties

 

Guess you like

Origin www.cnblogs.com/baobaoxiaokeai/p/10966693.html