栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

【Java】SpringBoot 之文档生成

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【Java】SpringBoot 之文档生成

part 1引入依赖
        
            io.springfox
            springfox-swagger2
            
            2.9.2 
        
            
part 2配置
import org.springframework.context.annotation.Configuration;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration	//前提 : 声明是配置文件类
@EnableSwagger2//作用在于开启 Swagger
public class SwaggerConfig {
    
    @Bean
    public Docket api(){
        return new Docket(documentationType.SWAGGER_2).select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo());
    }
	//可以设置相关信息 如标题 版本 描述
    public ApiInfo apiInfo(){
        return new ApiInfoBuilder().title("田浩然")
                .version("1.0.0")
                .description("牛逼")
                .build();
    }
}

apiInfo 展示

几个注解 @Api

​ 对接口进行描述,比如标签之类的

@ApiOperation

​ 对接口的方法进行描述

@ApiModel

​ 见名知意–声明实例说明

@ApiModelProperty

见名知意–声明实例属性

@ApiIgnore

​ 忽略某些接口

@ApiImplicitParam part 3访问 无 UI

​ http://localhost:8080/v2/api-docs

有 UI

http://localhost:8080/swagger-ui.html

效果展示

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/309590.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号