springboot 利用swagger生成在本文档

一、spring boot环境在这里不再重复,直接在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>

二、在入口类中,加入注解:@EnableSwagger2,以及加入swagger的信息###

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.basePackage("com.forezp.controller")).paths(PathSelectors.any()).build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("springboot利用swagger构建api文档").description("使用方法,http://www.jianshu.com/p/16c4b5a8c9ee").termsOfServiceUrl("http://blog.csdn.net/forezp").version("1.0").build();
    }

三、swagger访问地址:http://localhost/swagger-ui.html

- @Api()用于类名
- @ApiOperation()用于方法名 
- @ApiParam()用于参数说明 
- @ApiModel()用于实体类 
- @ApiModelProperty用于实体类属性
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容