springboot 利用swagger生成在本文档

2017-09-25  本文已影响0人  冷酷的温柔

一、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用于实体类属性
上一篇 下一篇

猜你喜欢

热点阅读