网站首页 > 编程文章 正文
最近开源项目中在集成swagger2,集成好之后发现UI效果很差,于是各种百度,发现了swagger-bootstrap-ui这个UI,于是开始了一波复制粘贴的操作,先来看以下效果:
之前的效果:
一、添加依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.6</version>
</dependency>
二 、新增swagger2配置文件
package com.democxy.common.config;
import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
/**
* swagger配置类
* @author shiling_deng
* @version 2021/04/15
*/
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
// 根据包名扫描接口,容易暴露不想公开的接口
// .apis(RequestHandlerSelectors.basePackage("com.democxy"))
// 根据注解扫描,建议使用这种方式,灵活性更高
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfo(
"EASYBOOT-ADMIN接口文档",
"springboot简易开发平台" ,
"V1.0.0",
"https://gitee.com/shuangerduo",new Contact("shiling_deng", "", ""),
"",
"https://gitee.com/shuangerduo",
new ArrayList<>()
);
}
}
三、启动项目
启动项目,不报错,然后访问地址: http://ip:port/doc.html 即可
如:http://localhost:8080/doc.html
注意事项
如果想要api文档在未登录的情况下查看,记得放行 /swagger-resources/** 路径以及处理webjars静态资源
Swagger常用注解
@ApiOperation
使用于该方法上,表示一个http请求的操作 源码中属性太多,这几个比较常用 value用于方法描述 notes用于提示内容 tags可以重新分组(视情况而用)
@ApiParam
使用在方法上或者参数上,字段说明;表示对参数的添加元数据(说明或是否必填等) name–参数名 value–参数说明 required–是否必填
@ApiModel()
使用在类上,表示对类进行说明,用于参数用实体类接收 value–表示对象名 description–描述
@ApiModelProperty()
使用在方法,字段上,表示对model属性的说明或者数据操作更改 value–字段说明 name–重写属性名字 dataType–重写属性类型 required–是否必填 example–举例说明 hidden–隐藏
猜你喜欢
- 2024-10-24 SpringBoot 集成 MyBatisPlus | 实战基础系列
- 2024-10-24 真香,GitLab 和 Docker自动化部署SpringBoot应用
- 2024-10-24 使用IDEA教你搭建Spring Boot简单项目
- 2024-10-24 Spring boot 自定义starter(springboot自定义starter步骤封装nacos)
- 2024-10-24 Spring Boot介绍及快速入门案例(spring boot.)
- 2024-10-24 跟武哥一起学习Spring Boot,一份全面详细的学习教程
- 2024-10-24 Spring Boot | 一种优雅的参数校验方案(个人总结)
- 2024-10-24 Spring Boot 统一接口响应格式的正确姿势!
- 2024-10-24 深入SpringBoot可执行Jar包:从Maven生命周期到自定义类加载器
- 2024-10-24 浅析一个较完整的SpringBoot项目(springboot项目运行原理)
你 发表评论:
欢迎- 06-24一个老爸画了超级有爱的365幅画 | 父亲节献礼
- 06-24产品小白看魏则西事件——用产品思维审视百度推广
- 06-24某教程学习笔记(一):13、脚本木马原理
- 06-24十大常见web漏洞——命令执行漏洞
- 06-24初涉内网,提权那些事(内网渗透提权)
- 06-24黑客命令第16集:47种最常见的**网站方法2/2
- 06-24铭说 | 一句话木马的多种变形方式
- 06-24Java隐藏的10倍效率技巧!90%程序员不知道的魔法方法(附代码)
- 最近发表
- 标签列表
-
- spire.doc (70)
- instanceclient (62)
- solidworks (78)
- system.data.oracleclient (61)
- 按键小精灵源码提取 (66)
- pyqt5designer教程 (65)
- 联想刷bios工具 (66)
- c#源码 (64)
- graphics.h头文件 (62)
- mysqldump下载 (66)
- libmp3lame (60)
- maven3.3.9 (63)
- 二调符号库 (57)
- git.exe下载 (68)
- diskgenius_winpe (72)
- pythoncrc16 (57)
- solidworks宏文件下载 (59)
- qt帮助文档中文版 (73)
- satacontroller (66)
- hgcad (64)
- bootimg.exe (69)
- android-gif-drawable (62)
- axure9元件库免费下载 (57)
- libmysqlclient.so.18 (58)
- springbootdemo (64)
本文暂时没有评论,来添加一个吧(●'◡'●)