swagger和springboot整合使用

pom.xml

 
            io.springfox
            springfox-swagger2
            2.8.0
        

        
            io.springfox
            springfox-swagger-ui
            2.8.0
        

创建配置类SwaggerConfig

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Value("${swagger.enable:true}")
    private boolean enableSwagger;

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .enable(enableSwagger)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.datbc.youpinchain.shop"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("youpinchain")
                .description("h5商城接口")
                .build();
    }
}

controller中给需要的接口加注解

之后访问:http://localhost:8080/swagger-ui.html

你可能感兴趣的:(java后台,插件)