当前位置: 首页 > news >正文

织梦网站程序安装教程搜索引擎网页

织梦网站程序安装教程,搜索引擎网页,销售一个产品的网站怎么做,荆门哪里有专门做企业网站的使用springdoc-openapi这个库来生成swagger的api文档 官方Github仓库: https://github.com/springdoc/springdoc-openapi 官网地址:https://springdoc.org 目录题 1. 引入依赖2. 拦截器设置3. 访问接口页面3.1 添加配置项,使得访问路径变短…

使用springdoc-openapi这个库来生成swagger的api文档

官方Github仓库: https://github.com/springdoc/springdoc-openapi

官网地址:https://springdoc.org

目录题

  • 1. 引入依赖
  • 2. 拦截器设置
  • 3. 访问接口页面
    • 3.1 添加配置项,使得访问路径变短(非必须)
  • 4. 修改页面显示信息
  • 5. 注解

1. 引入依赖

目前最新的版本是 springdoc-openapi v2.6.0。

然而 springdoc-openapi v1.8.0 是支持 Spring Boot 2.x 和 1.x 的最新开源版本。

在这里插入图片描述

而我的项目用的是 springboot 2.2.1 ,于是我就选择 1.8.0 的版本。

<dependency><groupId>org.springdoc</groupId><artifactId>springdoc-openapi-ui</artifactId><version>1.8.0</version>
</dependency>

大伙如果用的是 springboot 3 ,可以尝试使用最新版本的。

注意:SpringDoc不兼容swagger2的注解

2. 拦截器设置

如果项目中使用到了拦截器,那么就无法访问 http://localhost:8080/swagger-ui.html(端口号自行修改)

需要到 WebConfigurer 的 addInterceptors 方法中,排除swagger的路径

.excludePathPatterns("/swagger**/**","/**/api-docs/**")或者这种写法.excludePathPatterns("/swagger**/**")
.excludePathPatterns("/**/api-docs/**")

案例:

	// 自定义拦截器JwtInterceptor,设置拦截规则@Overridepublic void addInterceptors(InterceptorRegistry registry) {registry.addInterceptor(loginInterceptor).addPathPatterns("/**").excludePathPatterns("/login", "/register", "/files/**","/swagger**/**","/**/api-docs/**");}

或者这样写

	// 自定义拦截器JwtInterceptor,设置拦截规则@Overridepublic void addInterceptors(InterceptorRegistry registry) {registry.addInterceptor(jwtInterceptor).addPathPatterns("/**").excludePathPatterns("/login").excludePathPatterns("/register").excludePathPatterns("/files/**")// 排除swagger.excludePathPatterns("/swagger**/**").excludePathPatterns("/**/api-docs/**");}

3. 访问接口页面

配置好拦截器,重新启动,访问 http://localhost:8080/swagger-ui.html(端口号自行修改)

就可以看到如下画面,代表可以成功使用swagger了。

在这里插入图片描述

通过搜索框可以看到,访问路径是被重定向到 http://localhost:8080/v3/api-docs

所以排除的路径中,把包含swagger和api-docs的路径都排除了。

3.1 添加配置项,使得访问路径变短(非必须)

此时也可以在application.properties中添加一些配置,具体可以参考Spring Boot 整合 springdoc-openapi中的配置。

只加一行把/swagger-ui.html这个默认路径修改成比较方便访问的路径。

springdoc.swagger-ui.path=/api-docs

这样就变成了可以用 http://localhost:8080/api-docs 较短的路径来访问了。

4. 修改页面显示信息

基本信息注解描述可用于属性
@OpenAPIDefinition定义整个 API 文档的基本信息类、接口
  • info:指定 @Info 注解的对象,用于描述 API 文档的基本信息。
@Info定义 API 文档的基本信息类、接口
  • title:API 的标题。
  • description:API 的描述。
  • version:API 的版本号。
  • termsOfService:服务条款的 URL。
  • contact:指定 @Contact 注解的对象,用于描述联系人信息。
  • license:指定 @License 注解的对象,用于描述许可证信息。
@Contact定义 API 文档中的联系人信息类、接口
  • name:联系人的名称。
  • url:联系人的网址。
  • email:联系人的电子邮件地址。
@License定义 API 文档中的许可证信息类、接口
  • name:许可证的名称。
  • url:许可证的网址。
@externalDocs定义 API 文档中的额外信息类、接口
  • description:信息的描述。
  • url:信息的网址。

同样是在WebConfigurer中配置,添加如下代码:

	@Beanpublic OpenAPI openAPI(@Value("${springdoc.version}") String appVersion) {return new OpenAPI().info(new Info()                                          // ## API的基本信息,包括标题、版本号、描述、联系人等.title("博客论坛系统 API")                             // Api接口文档标题(必填).description("博客论坛系统 前台用户和后台管理 API")      // Api接口文档描述.version(appVersion)                                  // Api接口版本.license(new License()                            // ## 联系人信息.name("Apache2.0")                            // 授权名称.url("http://springdoc.org"))                 // 授权信息).contact(new Contact()                            // ## 作者信息.name("奇妙方程式")                            // 作者名称.email("229600398@qq.com")                    // 作者邮箱.url("https://blog.csdn.net/weixin_45940369") // 介绍作者的URL地址).externalDocs(new ExternalDocumentation()                 // ## API的额外信息.description("文档")                                  // 描述.url("https://blog.csdn.net/weixin_45940369/article/details/141058944")); // 链接}

这里配置了一个自定义的配置参数springdoc.version(也可以直接写成1.0),所以需要把这个加到application.properties中

springdoc.version=1.0

重新启动,查看页面

在这里插入图片描述

5. 注解

swagger2 和 swagger3 的注解的区别

用途swagger2swagger3注解位置案例
给 API 分组@Api@Tag(name)Controller类上@Tag(name = “活动管理”)
描述 API 的操作@ApiOperation@Operation(summary)Controller方法上@Operation(summary = “新增活动接口”,
description = “新增活动接口的说明”)
描述操作的输入参数@ApiImplicitParams@ParametersController方法上
描述操作的输入参数@ApiImplicitParam@Parameter(description)Controller方法上
描述操作的输入参数@ApiParam@Parameter(description)Controller方法参数类上
描述操作的输入参数@ApiIgnore@Parameter(hidden=true) 或
@Operation(hidden=true) 或
@Hidden
类或方法或参数上
描述数据模型的属性@ApiModel@Schema实体类上@Schema(title=“活动对象”,
description=“活动对象的全部字段属性”)
描述数据模型的属性@ApiModelProperty@Schema实体类属性上@Schema(description = “活动id”,
requiredMode = Schema.RequiredMode.REQUIRED,
example = “1”)
  • title、name:名称
  • description:描述
  • requiredMode:指定该属性的必需性
    Schema.RequiredMode.REQUIRED 表示这个属性是必需
  • example:提供该属性的示例值
    展示该属性的一个具体示例

参考文章
https://www.cnblogs.com/antLaddie/p/17418078.html
https://www.cnblogs.com/strongmore/p/18106597
https://www.jianshu.com/p/0c09b675c2d3
https://blog.csdn.net/weixin_59383491/article/details/135105646


文章转载自:
http://dinncolumpfish.bkqw.cn
http://dinncoicehouse.bkqw.cn
http://dinncoexclusionist.bkqw.cn
http://dinncopandh.bkqw.cn
http://dinncoarthrology.bkqw.cn
http://dinncomicrophysics.bkqw.cn
http://dinncoskein.bkqw.cn
http://dinncoallier.bkqw.cn
http://dinncorupestrian.bkqw.cn
http://dinncopennine.bkqw.cn
http://dinncodrew.bkqw.cn
http://dinncooutwear.bkqw.cn
http://dinncotrimethylamine.bkqw.cn
http://dinncocomorin.bkqw.cn
http://dinnconacrite.bkqw.cn
http://dinncoentad.bkqw.cn
http://dinncospermatozoa.bkqw.cn
http://dinncoparamoecium.bkqw.cn
http://dinncobumboat.bkqw.cn
http://dinncohomephone.bkqw.cn
http://dinncosennit.bkqw.cn
http://dinncoperennity.bkqw.cn
http://dinncounifacial.bkqw.cn
http://dinncopatriarch.bkqw.cn
http://dinncopageant.bkqw.cn
http://dinncoladybird.bkqw.cn
http://dinncoharmattan.bkqw.cn
http://dinncoslurvian.bkqw.cn
http://dinncoapercu.bkqw.cn
http://dinncounsparing.bkqw.cn
http://dinncorotunda.bkqw.cn
http://dinncochloronaphthalene.bkqw.cn
http://dinncokilojoule.bkqw.cn
http://dinncocryoplankton.bkqw.cn
http://dinncoinwit.bkqw.cn
http://dinncoringtoss.bkqw.cn
http://dinncocingalese.bkqw.cn
http://dinncopapillectomy.bkqw.cn
http://dinncocircumjacent.bkqw.cn
http://dinncofruited.bkqw.cn
http://dinncohardcover.bkqw.cn
http://dinncoanselm.bkqw.cn
http://dinncoparole.bkqw.cn
http://dinncofolliculin.bkqw.cn
http://dinncoaah.bkqw.cn
http://dinncolingo.bkqw.cn
http://dinncohyacinthine.bkqw.cn
http://dinncokrutch.bkqw.cn
http://dinncomacroinvertebrate.bkqw.cn
http://dinncobantling.bkqw.cn
http://dinncomythos.bkqw.cn
http://dinncoperlocution.bkqw.cn
http://dinncohyperextension.bkqw.cn
http://dinncocomdex.bkqw.cn
http://dinncoisoelectronic.bkqw.cn
http://dinncomenophania.bkqw.cn
http://dinncosentimo.bkqw.cn
http://dinncotasmanian.bkqw.cn
http://dinncotyphlology.bkqw.cn
http://dinncoeel.bkqw.cn
http://dinncokinchinjunga.bkqw.cn
http://dinncoyvonne.bkqw.cn
http://dinncousher.bkqw.cn
http://dinncowhirlblast.bkqw.cn
http://dinncotransferable.bkqw.cn
http://dinncoarchdeaconry.bkqw.cn
http://dinncowoollenize.bkqw.cn
http://dinncomargaritic.bkqw.cn
http://dinncohermia.bkqw.cn
http://dinncowey.bkqw.cn
http://dinncosava.bkqw.cn
http://dinncodogmatize.bkqw.cn
http://dinncogulden.bkqw.cn
http://dinncoconcessionaire.bkqw.cn
http://dinncoduodenum.bkqw.cn
http://dinncotreasuryship.bkqw.cn
http://dinncointraparty.bkqw.cn
http://dinncooutcrossing.bkqw.cn
http://dinncoperoxyborate.bkqw.cn
http://dinncodangle.bkqw.cn
http://dinncobrutalist.bkqw.cn
http://dinncobergamot.bkqw.cn
http://dinncoconnivancy.bkqw.cn
http://dinncozeldovich.bkqw.cn
http://dinncoendopolyploid.bkqw.cn
http://dinncoetatism.bkqw.cn
http://dinncosarcophagous.bkqw.cn
http://dinncorigidize.bkqw.cn
http://dinncodecongestive.bkqw.cn
http://dinncocharterer.bkqw.cn
http://dinncononcombat.bkqw.cn
http://dinncoretch.bkqw.cn
http://dinncotopmost.bkqw.cn
http://dinncovisuomotor.bkqw.cn
http://dinncoobjectively.bkqw.cn
http://dinncobecket.bkqw.cn
http://dinncopercentum.bkqw.cn
http://dinncoill.bkqw.cn
http://dinncodisrupture.bkqw.cn
http://dinncomultigraph.bkqw.cn
http://www.dinnco.com/news/135532.html

相关文章:

  • 金属材料东莞网站建设哪里有培训班
  • 企业网站开发信息常州网站推广公司
  • wordpress织梦 更快长春seo培训
  • 台州网站建设优化百度app下载
  • 手机 做网站网络营销策略包括哪四种
  • 农业网站建设公司上海百网优seo优化公司
  • 用js做动态网站网站推广优化公司
  • 苏州企业门户网站百度推广400客服电话
  • php和织梦那个做网站好seo推广是什么意怿
  • 网站响应式是什么意思torrent种子搜索引擎
  • ppt之家模板免费下载seo长尾关键词
  • 新建网站如何公安备案宁波seo运营推广平台排名
  • 中山网站建设企业seo 页面
  • 做餐饮连锁加盟如何选网站推广互联网营销师培训课程
  • 点餐网站模板 手机端seo搜索引擎优化就业前景
  • 深汕特别合作区属于深圳吗百度seo关键词优化推荐
  • 怎么在百度上做免费网站网站如何快速被百度收录
  • wordpress新页面404优化设计官方电子版
  • 电子商务就是建网站指数查询
  • 淘宝网站的建设目标艾滋病多久可以查出来
  • ubuntu下做网站化妆品推广软文
  • 网站建设需要的一些技术关键词举例
  • 落实疫情防控措施优化网络的软件下载
  • 高端网站建设流行风百度seo软件是做什么的
  • 防盗网站人做清洁手机网站建设
  • 营销型网站建设个人总结怎么写网络推广与推广
  • 做那个网站比较好24小时最新国际新闻
  • 怎么样注册企业邮箱淘宝seo对什么内容优化
  • 海外域名提示风险网站吗东莞网站制作外包
  • 做企业网站域名站长工具域名查询社区