pom

  <modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description> <properties>
<java.version>1.8</java.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

controller

@RestController
@Api(value = "test", description = "测试demo")
public class DemoController { @ApiOperation(value = "根据ID查询", notes = "传入id")
@RequestMapping(value = "/test1", method = RequestMethod.GET)
public String getTest(String id) {
System.out.println(id);
Gson gson = new Gson();
List<String> list = new ArrayList<>();
list.add("1");
list.add("2");
list.add("3");
Demo demo = new Demo();
return gson.toJson(list);
}
}

swagger启动

@Configuration
@EnableSwagger2
public class SwaggerApp { @Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
//为当前包路径
.apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))
.paths(PathSelectors.any())
.build();
// return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)).build();
} //构建 api文档的详细信息函数,注意这里的注解引用的是哪个
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
//页面标题
.title("Spring Boot 使用 Swagger2 构建RESTful API")
//创建人
.contact(new Contact("Bryan", "http://blog.bianxh.top/", ""))
//版本号
.version("1.0")
//描述
.description("API 描述")
.build();
} }

默认测试访问地址

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

swagger案例Swagger案例的更多相关文章

  1. swagger & api & swagger ui

    swagger & api swagger ui # run server $ swagger project start api-app # call api $ curl http://1 ...

  2. 测试-Swagger:Swagger

    ylbtech-测试-Swagger:Swagger The Best APIs are Built with Swagger Tools. Swagger 是一款RESTFUL接口的文档在线自动生成 ...

  3. VR定制 AR定制 就找北京动软VR开发团队(VR案例 AR案例)

    我们长期承接丰交互软件.游戏项目外包: VR/AR内容应用定制.VR.AR游戏项目外包(有主流测试硬件设备) VR全景应用.视频外包 请提供贵公司的信息,我们将提供高大上的VR案例欢迎联系我们给您提供 ...

  4. Hive学习之四 《Hive分区表场景案例应用案例,企业日志加载》 详解

    文件的加载,只需要三步就够了,废话不多说,来直接的吧. 一.建表 话不多说,直接开始. 建表,对于日志文件来说,最后有分区,在此案例中,对年月日和小时进行了分区. 建表tracktest_log,分隔 ...

  5. RestFul风格API(Swagger)--从零开始Swagger

    引言:随着技术的革新,现在的系统基本上都是前后端分离,并且在各自的道路上越走越远,而前后端之间通信或者联系的桥梁就是API,而这里基于RESTful风格的API框架就来了!欲知后事如何,客官别急,往下 ...

  6. mysql 案例 ~ 常见案例汇总

    一 简介:这里汇总了一些mysql常见的问题二 案例场景   问题1 mysql设置了默认慢日志记录1S,为何会记录不超过1S的sql语句   答案 mysql~log_queries_not_usi ...

  7. SpringBoot集成Swagger(Swagger的使用),生成接口文档,方便前后端分离开发

    首先上一张成果图.  1.Maven依赖 <dependency> <groupId>io.springfox</groupId> <artifactId&g ...

  8. .NetCore(.NET6)中使用swagger和swagger版本控制

    一..NET6中使用swagger swagger支持 API 自动生成同步的在线文档,下面在.NET6中引入 1.建.NET6应用并建以下控制器 /// <summary> /// 订单 ...

  9. 跟着百度学PHP[15]-SESSION的应用/网站登陆案例完整案例

    先把几个应该要有的页面建立好.

随机推荐

  1. Elastic 使用索引生命周期管理实现热温冷架构

    Elastic: 使用索引生命周期管理实现热温冷架构 索引生命周期管理 (ILM) 是在 Elasticsearch 6.6(公测版)首次引入并在 6.7 版正式推出的一项功能.ILM 是 Elast ...

  2. Hyper V NAT 网络设置 固定IP / DHCP

    Hyper V 默认的Default Switch同时支持了NAT网络以及DHCP,虚拟机能够访问外网. 但使用过程中发现这个IP网段经常变化,而且Hyper V没有提供管理其NAT网络与DHCP的图 ...

  3. Flask笔记:session

    session与cookie: cookie是一项浏览器的技术,而不是服务器的技术,服务器端是无法直接操作cookie的,只能通过返回Response响应告诉浏览器怎么操作cookie.而sessio ...

  4. Java开发设计——UML类图

    Java开发设计——UML类图 摘要:本文主要介绍了UML类图的相关知识. 简介 在UML中,类使用包含类名.属性和操作且带有分隔线的长方形来表示,类图分为三层. 第一层是类的名称,如果是抽象类或接口 ...

  5. 在vue项目中通过iframe引入jquery项目

    最近公司因为原来的jq框架存在的问题太多,所以要进行主题框架的重新搭建,我使用的vue进行的主题框架的重新搭建,但是原来的页面已经完成很多了,而且都是使用的jquery进行开发的 在vue中引入jqu ...

  6. 【AI测试】也许这有你想知道的人工智能 (AI) 测试--第二篇

    概述此为人工智能 (AI) 测试第二篇 第一篇主要介绍了 人工智能测试.测试什么.测试数据等.第二篇主要介绍测试用例和测试报告.之后的文章可能具体介绍如何开展各项测试,以及具体项目举例如何测试.测试用 ...

  7. 2.监控软件zabbix-客户端安装

    环境准备 Zabbix-Agent只要http://www.zabbix.com/download.php中可以下载的Zabbix-Agent均可以搭建Zabbix-Agent环境,本文选用CentO ...

  8. X264-视频帧的存取

    X264的编码器结构体x264_t中的子结构体字段frames包含了4个临时视频帧序列空间:current.next.unused和reference,分别保存当前编码帧.将编码帧序列.未处理原始视频 ...

  9. LNK1104 无法打开文件“xxx.lib”

    尝试解决方法: 1.找到这个库,把这个库移动到特定的文件夹下,在属性中添加这个库: 具体来说:打开VS项目->项目属性->配置属性->C/C+±>附加包含目录->编辑-& ...

  10. 201871010109-胡欢欢《面向对象程序设计(java)》第十三周学习总结

    项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/nwnu-daizh/p ...