swagger案例Swagger案例
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案例的更多相关文章
- swagger & api & swagger ui
swagger & api swagger ui # run server $ swagger project start api-app # call api $ curl http://1 ...
- 测试-Swagger:Swagger
ylbtech-测试-Swagger:Swagger The Best APIs are Built with Swagger Tools. Swagger 是一款RESTFUL接口的文档在线自动生成 ...
- VR定制 AR定制 就找北京动软VR开发团队(VR案例 AR案例)
我们长期承接丰交互软件.游戏项目外包: VR/AR内容应用定制.VR.AR游戏项目外包(有主流测试硬件设备) VR全景应用.视频外包 请提供贵公司的信息,我们将提供高大上的VR案例欢迎联系我们给您提供 ...
- Hive学习之四 《Hive分区表场景案例应用案例,企业日志加载》 详解
文件的加载,只需要三步就够了,废话不多说,来直接的吧. 一.建表 话不多说,直接开始. 建表,对于日志文件来说,最后有分区,在此案例中,对年月日和小时进行了分区. 建表tracktest_log,分隔 ...
- RestFul风格API(Swagger)--从零开始Swagger
引言:随着技术的革新,现在的系统基本上都是前后端分离,并且在各自的道路上越走越远,而前后端之间通信或者联系的桥梁就是API,而这里基于RESTful风格的API框架就来了!欲知后事如何,客官别急,往下 ...
- mysql 案例 ~ 常见案例汇总
一 简介:这里汇总了一些mysql常见的问题二 案例场景 问题1 mysql设置了默认慢日志记录1S,为何会记录不超过1S的sql语句 答案 mysql~log_queries_not_usi ...
- SpringBoot集成Swagger(Swagger的使用),生成接口文档,方便前后端分离开发
首先上一张成果图. 1.Maven依赖 <dependency> <groupId>io.springfox</groupId> <artifactId&g ...
- .NetCore(.NET6)中使用swagger和swagger版本控制
一..NET6中使用swagger swagger支持 API 自动生成同步的在线文档,下面在.NET6中引入 1.建.NET6应用并建以下控制器 /// <summary> /// 订单 ...
- 跟着百度学PHP[15]-SESSION的应用/网站登陆案例完整案例
先把几个应该要有的页面建立好.
随机推荐
- Python Jupyter 网站编辑器
Python Jupyter 网站编辑器 jupyter 是 python的网站编辑器可以直接在网页内编写python代码并执行,内置是通过ipython来调用的.很方便灵活. 安装 1.安装ipyt ...
- 关于@Autowired后Spring无法注入的问题
1.对于新手来说,最明显的不过是在applicationContext.xml文件上没有加<context:component-scan base-package="com.xxx&q ...
- Java开发中对Redis的基本操作
Jedis操作redis指令 import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; impo ...
- Bootstrap-table表格插件的使用方法
前言 上次写了一个可拖动列表的插件,但除了这个特点没什么优点了,接下写的是我们常用的Bootstrap-table表格插件 正文 官网:https://bootstrap-table.com/ 有两个 ...
- JavaWeb之文件上传和下载
在如今的互联网时代,人们越来越喜欢将自己的数据存放到互联网上,于是便诞生了很多类型的软件,比如360网盘,百度网盘,云盘之类的.所以说,文件上传和下载的功能是现在非常主流的一个功能,应用十分广泛. 那 ...
- HeadFirst设计模式--命令模式
模式定义 命令模式(Command Pattern):将一个请求封装为一个对象,从而使我们可用不同的请求对客户进行参数化:对请求排队或者记录请求日志,以及支持可撤销的操作.命令模式是一种对象行为型模式 ...
- centos安装elasticsearch-rtf5.5.4
安装jdk 我的博文里面有 https://www.cnblogs.com/vinic-xxm/p/11825691.html 安装elasticsearch-rtf git clone git:// ...
- Django框架(十八)—— drf:序列化组件(serializer)
序列化组件 # 模型层 from django.db import models class Book(models.Model): nid = models.AutoField(primary_ke ...
- 02微信小程序-轮播的宽度100%显示和轮播的基础配置
1==>如何让轮播的宽度100%显示? 你先给swiper 外面添加一个大盒子,给大盒子一个类 . <view class='lunbobox'> 然后wxss 里面设置 image ...
- Maven 中 dependencyManagement 元素,知识点
Maven 提供的 dependencyManagement 元素既能让子模块继承到父模块的依赖配置,又能保证子模块依赖使用的灵活性.在 dependencyManagement 元素下的依赖声明不会 ...