Swagger

1. 配置

  • pom文件添加swagger依赖,注意版本,2.8.0可以使用
    <dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
  • 新建一个配置类,添加以下内容和注解(注意修改相关的内容,比如包)
@Configuration
@EnableSwagger2
public class Swagger2Setting {
@Bean
public Docket createRestAPI(){
return new Docket(DocumentationType.SWAGGER_2)
//.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.crab.classfight.controller"))
.paths(PathSelectors.any())
.build();
} private ApiInfo apiInfo(){
return new ApiInfoBuilder()
.title("classfight项目")
.description("这里是classfight项目的API列表说明")
.contact("crab")
.version("1.0")
.build();
}
}
  • 开发restful风格的接口,例如:
    @DeleteMapping(value = "/deleteUser/{username}")
@ApiOperation("删除一个用户")
public void deleteUser(@PathVariable("username") String username){
userService.deleteUserByName(username); }
  • 编写注释文档,例如:

    • 在rest接口上使用@Api注解:
    @RestController
@Api("用户相关的API")
public class UserController {
}
- 在方法上使用@ApiOperation注解:
` @ApiOperation(value = "添加一个用户")`
- 方法参数注解
@ApiParam或者
```
@ApiImplicitParams({
@ApiImplicitParam(name = "userName", required = true, value = "输入用户名关键字", dataType = "String"),
@ApiImplicitParam(name = "courseId", required = true, value = "当前报名的课程id", dataType = "String")
})
    - 在实体类上使用@ApiModelProperty注解,可选参数(name, value, required, hidden, default value)
还有相关其他的注解,这里不举例了
- 运行项目,进入网址http://localhost:8080/swagger-ui.html查看接口信息文档,测试接口。 ### Postman
- 去Postman官网下载并安装,运行项目,在Postman中按照请求方式输入网址和请求参数,测试。
- 可以选择相应的请求方式,然后在body中添加相应的参数,点击send查看返回结果。
![](https://img2018.cnblogs.com/blog/1369152/201903/1369152-20190320213332813-1176174412.png)

Swagger和Postman的配置和使用的更多相关文章

  1. 浅入深出Vue:工具准备之PostMan安装配置及Mock服务配置

    浅入深出Vue之工具准备(二):PostMan安装配置 由于家中有事,文章没顾得上.在此说声抱歉,这是工具准备的最后一章. 接下来就是开始环境搭建了~尽情期待 工欲善其事必先利其器,让我们先做好准备工 ...

  2. swagger的说明、配置及使用

    一.What is swagger? 官方介绍:Swagger是一个规范且完整的框架,提供描述.生产.消费和可视化RESTful Web Service.专业角度:Swagger是由庞大工具集合支撑的 ...

  3. Swagger整合Jwt授权配置

    Swagger整合Jwt授权配置 欢迎关注博主公众号「Java大师」, 专注于分享Java领域干货文章http://www.javaman.cn/sb2/swagger-jwt 一.Swagger入门 ...

  4. swagger的作用和配置使用

    纯API项目中 引入swagger可以生成可视化的API接口页面     引入包 nuget包: Swashbuckle.AspNetCore(最新稳定版) 配置 1.配置Startup类Config ...

  5. Docker镜像仓库Harbor之Swagger REST API整合配置

    转载自:https://cloud.tencent.com/developer/article/1010618 1.Swagger 介绍 Swagger 是一个规范和完整的框架,用于生成.描述.调用和 ...

  6. .net core 配置Swagger 摆脱PostMan,你值得拥有这样的api调试方式

    废话不多说直接来看 第一步: 安装nuget包:Swashbuckle.AspNetCore.Swagger Swashbuckle.AspNetCore.SwaggerGen Swashbuckle ...

  7. Swagger 2.0 集成配置

    传统的API文档编写存在以下几个痛点: 对API文档进行更新的时候,需要通知前端开发人员,导致文档更新交流不及时: API接口返回信息不明确 大公司中肯定会有专门文档服务器对接口文档进行更新. 缺乏在 ...

  8. Swagger与postman使用心得

    Swagger接口文档,在线自动生成模板和页面.服务器地址加上swagger-ui.html后缀即可访问到(https://域名:端口号/swagger-ui.html). 使用时在java代码中引用 ...

  9. SpringBoot集成Swagger,Postman,newman,jenkins自动化测试.

    环境:Spring Boot,Swagger,gradle,Postman,newman,jenkins SpringBoot环境搭建. Swagger简介 Swagger 是一款RESTFUL接口的 ...

随机推荐

  1. Java笔记--引用类型的使用

    使用引用类型的一般步骤: 1.导包:指定需要使用的目标在什么位置,在publicclass之前一行写代码 import 包名路径 2.创建:通常需要创建之才能使用,格式: 数据类型 变量名称 = ne ...

  2. HotSpot设计原理与实现:一、初识HotSpot

    一.HotSpot内核模块组成和功能框架 1.HotSpot内核模块图 (1)Prims模块: (2)Service模块: (3)Runtime模块: 二.虚拟机生命周期(JVM初始化过程) 1.虚拟 ...

  3. springcloud第三步:发布服务消费者

    服务消费者 创建项目sercice-order Maven依赖 <parent> <groupId>org.springframework.boot</groupId&g ...

  4. 时间、日历(time、calendar、datatime)

    import time import calendar import datatime #获取代码运行的时间差 start = time.time() end = time.time() print( ...

  5. VS2017 异常 Editor or Editor Extension

    KE遇到的第一个问题 VS 2017 打开文件的时候, 遇到异常 检查 activity_log发现是 Editor or Editor Extension, 解决办法: 安装插件, Clear ME ...

  6. HDU 3586 二分答案+树形DP判定

    HDU 3586 『Link』HDU 3586 『Type』二分答案+树形DP判定 ✡Problem: 给定n个敌方据点,1为司令部,其他点各有一条边相连构成一棵树,每条边都有一个权值cost表示破坏 ...

  7. JAVA多线程实现的四种方式(转自https://www.cnblogs.com/felixzh/p/6036074.html)

    Java多线程实现方式主要有四种:继承Thread类.实现Runnable接口.实现Callable接口通过FutureTask包装器来创建Thread线程.使用ExecutorService.Cal ...

  8. Unityd外发光Shader Lab

    Shader "Faye/OutLightting" { Properties { _MainTex("Texture (RGB)", 2D) = " ...

  9. asp.net core mvc 在中间件中使用依赖注入问题:System.InvalidOperationException: Cannot resolve scoped service 'IXXXService' from root provider.

    今天在弄JWT的时候需要用到用户验证使用一个自己写好的验证,但在出现了:System.InvalidOperationException: Cannot resolve scoped service ...

  10. Junit4 之 Assert 静态方法介绍

    Junit中的assert方法全部放在Assert类中,总结一下junit类中assert方法的分类. 1.assertTrue/False([String message,]boolean cond ...