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

网站源码上传怎么创建网页链接

网站源码上传,怎么创建网页链接,做企业网站好的,新疆建设兵团疫情情况最新消息Spring Boot 3项目集成Swagger3教程 ?? 前言 欢迎来到我的小天地,这里是我记录技术点滴、分享学习心得的地方。?? ?? 技能清单 编程语言:Java、C、C、Python、Go、前端技术:Jquery、Vue.js、React、uni-app、EchartsUI设计: Element-u…

Spring Boot 3项目集成Swagger3教程

?? 前言

欢迎来到我的小天地,这里是我记录技术点滴、分享学习心得的地方。??

?? 技能清单
  • 编程语言:Java、C、C++、Python、Go、
  • 前端技术:Jquery、Vue.js、React、uni-app、Echarts
  • UI设计: Element-ui、Antd、Color-ui
  • 后端技术:Spring Boot、Mybatis-plus、Swagger
  • 移动开发:Android
  • 操作系统:Windows、Linux
  • 开发框架:RuoYi、微信小程序
  • 开发工具:VSCode、IDEA、Eclipse、WebStorm、HbuildX、Navicat、Xshell、Android Studio、Postman
  • 数据库技术:MySQL、Redis、SQL Server
  • 版本控制:Git

Swagger是一个用于设计、构建、记录和使用RESTful web服务的开源软件框架。Swagger 3(OpenAPI 3.0)提供了更加强大和灵活的API文档生成能力。本教程将指导您如何在Spring Boot 3项目中集成Swagger3,并使用Knife4j作为UI界面。

1. 添加依赖

首先,您需要在项目的pom.xml文件中添加Swagger3的依赖。同时,为了确保依赖能够正确下载,您可以添加阿里云的Maven镜像仓库。

        <!--swagger3--><dependency><groupId>com.github.xiaoymin</groupId><artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId><version>4.1.0</version></dependency><repositories><!--阿里云镜像--><repository><id>alimaven</id><name>aliyun maven</name><url>https://maven.aliyun.com/nexus/content/groups/public/</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></repository></repositories>

2. 配置Swagger

在Spring Boot项目中创建一个配置类SwaggerConfig,并添加Swagger的配置信息。

import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class SwaggerConfig {@Beanpublic OpenAPI springShopOpenAPI() {return new OpenAPI().info(new Info().title("标题").contact(new Contact()).description("我的API文档").version("v1").license(new License().name("Apache 2.0").url("http://springdoc.org"))).externalDocs(new ExternalDocumentation().description("外部文档").url("https://springshop.wiki.github.org/docs"));}
}

3. 实体类和控制层注解

在您的实体类和控制层中使用Swagger注解来描述API。

// 实体类注解示例
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;import java.util.Date;@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@Schema(name = "Employee", description = "$!{table.comment}")
public class Emp {@ExcelProperty("ID")@Schema(description = "ID")private int id;@ExcelProperty("用户名")@Schema(description = "用户名")private String names;@ExcelProperty("工资")@Schema(description = "工资")private double salary;@ExcelProperty("生日")@Schema(description = "生日")private Date birthday;@ColumnWidth(20)@ExcelProperty("头像")@Schema(description = "头像")private String photo;//    @ColumnWidth(20)
//    @DateTimeFormat("yyyy-MM-dd HH:mm:ss")
//    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
//    @ExcelProperty("创建日期")
//    private Date u_create_time;
}// 控制层注解示例
import io.swagger.v3.oas.annotations.Operation;@Operation(summary = "获取所有员工信息")
@GetMapping("/selectAll")
public List<Emp> selectAll() {// ...
}

4. 通用返回结果封装

创建一个通用的返回结果类,用于统一API的响应格式。

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;@Builder(toBuilder = true)
@AllArgsConstructor
@Setter
@Getter
@Slf4j
public class Result<T> {/*** 提示信息*/@Schema(description = "提示信息")private String message;/*** 是否成功*/@Schema(description = "是否成功")private boolean success;/*** 返回状态码*/@Schema(description = "返回状态码")private Integer code;/*** 数据*/@Schema(description = "数据")private T data;public Result() {}public static Result success() {Result Result = new Result();Result.setSuccess(Boolean.TRUE);Result.setCode(ResultCode.SUCCESS.getCode());Result.setMessage(ResultCode.SUCCESS.getMsg());return Result;}public static Result success(String msg) {Result Result = new Result();Result.setMessage(msg);Result.setSuccess(Boolean.TRUE);Result.setCode(ResultCode.SUCCESS.getCode());return Result;}public static Result success(Object data) {Result Result = new Result();Result.setData(data);Result.setSuccess(Boolean.TRUE);Result.setCode(ResultCode.SUCCESS.getCode());Result.setMessage(ResultCode.SUCCESS.getMsg());return Result;}/*** 返回失败 消息** @return Result*/public static Result failure() {Result Result = new Result();Result.setSuccess(Boolean.FALSE);Result.setCode(ResultCode.FAILURE.getCode());Result.setMessage(ResultCode.FAILURE.getMsg());return Result;}/*** 返回失败 消息** @param msg 失败信息* @return Result*/public static Result failure(String msg) {Result Result = new Result();Result.setSuccess(Boolean.FALSE);Result.setCode(ResultCode.FAILURE.getCode());Result.setMessage(msg);return Result;}public static Result failure(Integer code, String msg) {Result Result = new Result();Result.setSuccess(Boolean.FALSE);Result.setCode(code);Result.setMessage(msg);return Result;}public static Result failure(String msg, ResultCode exceptionCode) {Result Result = new Result();Result.setMessage(msg);Result.setSuccess(Boolean.FALSE);Result.setCode(exceptionCode.getCode());Result.setData(exceptionCode.getMsg());return Result;}/*** 返回失败 消息** @param exceptionCode 错误信息枚举* @return Result*/public static Result failure(ResultCode exceptionCode) {Result Result = new Result();Result.setSuccess(Boolean.FALSE);Result.setCode(exceptionCode.getCode());Result.setMessage(exceptionCode.getMsg());return Result;}/*** 返回失败 消息** @param exceptionCode 错误信息枚举* @param msg           自定义错误提示信息* @return Result*/public static Result failure(ResultCode exceptionCode, String msg) {Result Result = new Result();Result.setMessage(msg);Result.setSuccess(Boolean.FALSE);Result.setCode(exceptionCode.getCode());return Result;}}

5. 注解说明

Swagger3的注解与Swagger2有所不同,以下是一些常用注解的对照表:

Swagger2注解

Swagger3注解

注解位置

@Api

@Tag(name = “接口类描述”)

Controller类上

@ApiOperation

@Operation(summary = “接口方法描述”)

Controller方法上

@ApiImplicitParams

@Parameters

Controller方法上

@ApiImplicitParam

@Parameter(description = “参数描述”)

Controller方法上

@ApiParam

@Parameter(description = “参数描述”)

方法参数上

@ApiIgnore

@Parameter(hidden = true) 或 @Operation(hidden = true)

-

@ApiModel

@Schema

DTO类上

@ApiModelProperty

@Schema

DTO属性上

6. 访问Swagger UI

启动您的Spring Boot应用后,您可以通过以下地址访问Swagger UI:

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

在这里,您可以查看API文档,测试API接口,并获取相关信息。

?? 获取源代码

  • 后端案例:https://gitee.com/bestwishes0203/Front-end-example
  • 前端案例:https://gitee.com/bestwishes0203/Back-end-example

?? 联系方式

如果您对我们的项目感兴趣,或者有任何技术问题想要探讨,欢迎通过以下方式与我联系。我非常期待与您交流,共同学习,共同进步!

  • 邮箱:2109664977@qq.com
  • Gitee:https://gitee.com/bestwishes0203
  • GitHub:https://github.com/bestwishes0203
  • CSDN:https://blog.csdn.net/interest_ing_/
  • 个人博客:访问我的博客

?? 结语

感谢你的访问,如果你对我的技术文章或项目感兴趣,欢迎通过以上方式与我联系。让我们一起在技术的道路上不断前行!??


文章转载自:
http://dinncoportacabin.tpps.cn
http://dinncocolouration.tpps.cn
http://dinncoelisor.tpps.cn
http://dinncoratafee.tpps.cn
http://dinncoevert.tpps.cn
http://dinncoloamless.tpps.cn
http://dinnconegotiation.tpps.cn
http://dinncobywalk.tpps.cn
http://dinncocinc.tpps.cn
http://dinncohypoglycemic.tpps.cn
http://dinncobrinded.tpps.cn
http://dinncometeoric.tpps.cn
http://dinncocalciferol.tpps.cn
http://dinncofission.tpps.cn
http://dinncoreverberation.tpps.cn
http://dinncopantoum.tpps.cn
http://dinncounplug.tpps.cn
http://dinncopoorboy.tpps.cn
http://dinncohutung.tpps.cn
http://dinncoequitableness.tpps.cn
http://dinncothromboxane.tpps.cn
http://dinncoshareout.tpps.cn
http://dinncoautocorrelation.tpps.cn
http://dinncokindjal.tpps.cn
http://dinncofeelthy.tpps.cn
http://dinncogod.tpps.cn
http://dinncoastrodynamics.tpps.cn
http://dinncoatenism.tpps.cn
http://dinncoelectroplating.tpps.cn
http://dinncosoldier.tpps.cn
http://dinncodisco.tpps.cn
http://dinncocamoufleur.tpps.cn
http://dinncoeiderdown.tpps.cn
http://dinncocombine.tpps.cn
http://dinnconsa.tpps.cn
http://dinncodissimulate.tpps.cn
http://dinncohyposulfite.tpps.cn
http://dinncohook.tpps.cn
http://dinncogranulous.tpps.cn
http://dinncoprestigious.tpps.cn
http://dinncohttpd.tpps.cn
http://dinncogone.tpps.cn
http://dinncometallographic.tpps.cn
http://dinncopurulence.tpps.cn
http://dinncolaurustinus.tpps.cn
http://dinncotribulate.tpps.cn
http://dinncograpery.tpps.cn
http://dinncostriker.tpps.cn
http://dinncoconcessively.tpps.cn
http://dinncoavertable.tpps.cn
http://dinncorecense.tpps.cn
http://dinncobackslap.tpps.cn
http://dinncoredeveloper.tpps.cn
http://dinncondp.tpps.cn
http://dinncohesperides.tpps.cn
http://dinncocapriform.tpps.cn
http://dinncoquarters.tpps.cn
http://dinncovelma.tpps.cn
http://dinncopetrological.tpps.cn
http://dinncospaniard.tpps.cn
http://dinncoamygdala.tpps.cn
http://dinncolowest.tpps.cn
http://dinncoalastair.tpps.cn
http://dinncomyriameter.tpps.cn
http://dinncokept.tpps.cn
http://dinncoorville.tpps.cn
http://dinncocassette.tpps.cn
http://dinncokleig.tpps.cn
http://dinncomuckamuck.tpps.cn
http://dinncoamatol.tpps.cn
http://dinncoanalyzable.tpps.cn
http://dinncoquinine.tpps.cn
http://dinncoantiquate.tpps.cn
http://dinncoeon.tpps.cn
http://dinncovinton.tpps.cn
http://dinncocredential.tpps.cn
http://dinnconeighbouring.tpps.cn
http://dinncoenophthalmos.tpps.cn
http://dinncouninucleate.tpps.cn
http://dinncogiddyhead.tpps.cn
http://dinncosparsity.tpps.cn
http://dinncodisagreeable.tpps.cn
http://dinncopaddleball.tpps.cn
http://dinncounfashionable.tpps.cn
http://dinncobuckaroo.tpps.cn
http://dinncoairspeed.tpps.cn
http://dinncofloriculturist.tpps.cn
http://dinncoopah.tpps.cn
http://dinncoflightiness.tpps.cn
http://dinncohacienda.tpps.cn
http://dinncovaletudinarian.tpps.cn
http://dinncomeatball.tpps.cn
http://dinncofume.tpps.cn
http://dinncogirlygirly.tpps.cn
http://dinncobeckoningly.tpps.cn
http://dinncoaggravating.tpps.cn
http://dinncoopenhearted.tpps.cn
http://dinncoexpertly.tpps.cn
http://dinncoredhibition.tpps.cn
http://dinnconzima.tpps.cn
http://www.dinnco.com/news/102302.html

相关文章:

  • 如何用python 做网站百度网盘官网入口
  • 高端网站建设的方案搜索关键词排名一般按照什么收费
  • 内江网站开发专业做网络推广的公司
  • 燕郊网站制作seo站内优化
  • 北京好的做网站公司快速排名精灵
  • 深圳网站建设价格多少武汉百度推广优化
  • 鸣蝉小程序制作平台seo网页优化平台
  • 做网站用centos还是ubuntu网络营销中的seo与sem
  • 去除 做网站就用建站之星谷歌三件套一键安装
  • 在线游戏网页版廊坊seo管理
  • 建设部网站资质升级公示建网站软件
  • 四川省建设厅门户网站营销网站设计
  • 智慧团建网站登陆平台百度指数在线查询小程序
  • 删除网站死链精准大数据获客系统
  • 企业网络服务长沙专业竞价优化首选
  • 深圳哪家网站建设好网络营销推广方案怎么写
  • wordpress企业魔板seo外链网
  • app store怎么调回中文福州seo技术培训
  • 外包网站设计产品营销推广
  • 用明星名字做网站最有效的恶意点击
  • 深圳flash网站建设内容营销平台有哪些
  • 极路由 做网站太原网站建设方案优化
  • 网站地图是怎么做的长沙网站优化公司
  • 外围网站怎么做艾滋病阻断药
  • 国内网站做得好的公司网络营销平台排名
  • 乌鲁木齐做网站优化小说引流推广
  • 梧州网站建设厂家站长工具seo优化
  • 做公司网站首页bt磁力搜索器
  • 湖北网站推广策略营销咨询服务
  • 网站首页做了一下调整会被k吗百度推广开户