【Swagger】Knife4j美化Swagger

news/2024/9/28 13:15:10 标签: zookeeper, java, intellij-idea

关于项目中配置Swagger,可以参考点击,本文主要针对Knife4j【官网】进行描述

在这里插入图片描述

核对下自己使用的SpringBoot的版本,2.**和3*分别相对应

在这里插入图片描述

项目结构

在这里插入图片描述
1 父模块的pom中

         <properties>
             <!-- knife4j 版本-->
            <knife4j.version>2.0.7</knife4j.version>
         </properties>
          <dependency>
                <groupId>com.github.xiaoymin</groupId>
                <artifactId>knife4j-spring-boot-starter</artifactId>
                <!--在引用时请在maven中央仓库搜索2.X最新版本号-->
                <version>${knife4j.version}</version>
            </dependency>

2 子模块pom

<!--knife4j 增强 Swagger UI-->
        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>knife4j-spring-boot-starter</artifactId>
        </dependency>

然后在maven中 reload project ,加载新包

测试

1 在common 项目中配置config 包,创建SwaggerConfiguration 类
在这里插入图片描述
2 复制 点击
在这里插入图片描述
代码部分内容可以自定义改

@Configuration//Spring扫描
@EnableSwagger2//swagger注解
public class SwaggerConfiguration {

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

 private ApiInfo apiInfo() {
     return new ApiInfoBuilder()
     .title("swagger-bootstrap-ui RESTful APIs")
     .description("swagger-bootstrap-ui")
     .termsOfServiceUrl("http://localhost:8999/")
     .contact("developer@mail.com")
     .version("1.0")
     .build();
 }
}

3 测试

swagger-bootstrap-ui默认访问地址是:http:// h o s t : {host}: host:{port}/doc.html
http://localhost:8080/doc.html

在这里插入图片描述


http://www.niftyadmin.cn/n/1472820.html

相关文章

HDFS简介

1.HDFS介绍 HDFS 为了做到可靠性( reliability ) 创建了多份数据块&#xff08;data blocks&#xff09;的复制&#xff08;replicas&#xff09; &#xff0c;并将它们放置在服务器群的计算节点中&#xff08;compute nodes&#xff09;&#xff0c;MapReduce就可以在它们所在…

【解决】idea项目不报错 启动时却提示一堆程序包找不到

项目结构 一个Spring Boot 工程下&#xff0c;有两个子模块&#xff0c;其实所有的包均存在&#xff0c;但是一旦更改子模块中的某些内容&#xff0c;就会报一大堆 程序包找不到 的异常。 问题出现原因 maven并没有直接去导入代码里面的包&#xff0c;需要手动导入。这个问题&a…

Containerpilot 配置文件 之 Telemetry

如果提供telemetry选项&#xff0c;ContainerPilot将公开可用于刮擦性能telemetry的Prometheus HTTP客户端界面。 telemetry接口被公告为consul服务。 telemetry服务的每个metric为Prometheus客户端库配置收集器。 然后&#xff0c;Prometheus服务器可以向telemetry终端发出HTT…

【SpringBoot】配置统一异常处理类

项目结构 异常处理类在 common 子模块中使用 GlobalExceptionHandler代码 import com.snnu.response.Result; import com.snnu.response.ResultCode; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.Exce…

【SpringBoot+MyBatis-plus】后台分页操作

这里记录下IDEA中使用SpringBoot Mybatis-plus 如何进行分页操作 可参看官方文档 点击进入 1 确保已经在工程中引入了 Mybatis-plus 依赖 <dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-generator</artifactId><!…

使用函数指针模拟C++多态

1 #include <iostream>2 using namespace std;3 4 class Base5 {6 public :7 void display()8 {9 cout << "Base display" << endl; 10 } 11 12 void (Base :: **VTable)();//指向虚表的函数指针 13 int a; 14 }; 1…

axios请求后台

本文记录使用axios请求后台的操作&#xff0c;可参看文档 进入 1 下载 axios 相关包 在 Idea 控制台输入&#xff0c;如果npm不能直接下载相关的辅助包&#xff0c;则推荐查看博文 1 安装 axios: npm install axios 2 刷新项目中的包: npm install 3 发布前端工程: npm run…

[c/c++] programming之路(6)、ASCII码,数据类型、随机数、字符转换及拼接等

一、变量 1 #include<stdio.h>2 #include<stdlib.h>3 4 void main0(){5 //数据使用必须在范围内&#xff0c;否则产生溢出6 unsigned short num655351;//1之后溢出为07 //printf("%d",sizeof(num));8 printf("阿飞有%d元",num…