//此处省略springboot创建过程

1.引入swagger相关依赖(2个依赖必须版本相同)
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.1.2</version>
</dependency>
2.写个配置类;该类的位置和启动类平级
@Configuration
@EnableSwagger2
public class Swagger2Configure {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.demo.controller")) //包名一般用controller层
.paths(PathSelectors.any())
.build();
}
//下面的标题,描述,版本跟上面的包名可以配置在application.yml中,然后使用@Value注解取值
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("demo")//标题
.description("测试") //描述
.version("1.0")//版本
.build();
} }
//编写controller
@Controller
@Api(value ="订单",description ="订单相关接口" ) //API注解是用来对类进行描述
public class ShopOrderController { private final static Logger logger = LoggerFactory.getLogger(ShopOrderController.class);
@Autowired
private IOrderMastService orderMastService; @RequestMapping(value = "shop/order/{orderId}",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value ="订单查询",notes ="通过订单号查询对应的订单",httpMethod ="POST")//对该方法进行说明
public ShopOrderMast findOrderMastByOrderId(@PathVariable("orderId") String orderId){
return orderMastService.getOrderMastByOrderId(orderId);
} @RequestMapping(value = "shop/order/list",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value ="订单列表",notes ="订单列表分页查询",httpMethod ="POST")//对该方法进行说明
public PageInfo<ShopOrderMast> findOrderMastByOrderId(@RequestBody OrderQueryObject queryObject){
return orderMastService.selectOrderList(queryObject);
}
} //此时在浏览器打开http://localhost:2300/swagger-ui.html#/ (ip和端口根据自己的项目来定,我搭的项目用的是2300端口)
swagger相关的api,掌握4个就够用了
@Api(value ="订单",description ="订单相关接口" ) //API注解是用来对类进行描述
@ApiOperation(value ="订单查询",notes ="通过订单号查询对应的订单",httpMethod ="POST")//对该方法进行说明
@ApiIgnore用于不想生生成接口文档的类或者方法上
注意:即时没有以上4个注解,一样是可以生成swgger文档,只是没有相关的描述而已

public class OrderQueryObject extends QueryObject {
@ApiModelProperty("订单状态")//用于对象的字段进行描述
private int orderStatu; public int getOrderStatu() {
return orderStatu;
} public void setOrderStatu(int orderStatu) {
this.orderStatu = orderStatu;
}
}

效果如下:

springboot集成swagger文档的更多相关文章

  1. SpringBoot系列:六、集成Swagger文档

    本篇开始介绍Api文档Swagger的集成 一.引入maven依赖 <dependency> <groupId>io.springfox</groupId> < ...

  2. .NET Core基础篇之:集成Swagger文档与自定义Swagger UI

    Swagger大家都不陌生,Swagger (OpenAPI) 是一个与编程语言无关的接口规范,用于描述项目中的 REST API.它的出现主要是节约了开发人员编写接口文档的时间,可以根据项目中的注释 ...

  3. SpringBoot+SpringCloud+vue+Element开发项目——集成Swagger文档

    在pom.xml文件中添加Maven依赖 <!--swagger--> <dependency> <groupId>io.springfox</groupId ...

  4. spring boot集成swagger文档

    pom <!-- swagger --> <dependency> <groupId>io.springfox</groupId> <artifa ...

  5. asp.net core web api 生成 swagger 文档

    asp.net core web api 生成 swagger 文档 Intro 在前后端分离的开发模式下,文档就显得比较重要,哪个接口要传哪些参数,如果一两个接口还好,口头上直接沟通好就可以了,如果 ...

  6. Springboot系列(七) 集成接口文档swagger,使用,测试

    Springboot 配置接口文档swagger 往期推荐 SpringBoot系列(一)idea新建Springboot项目 SpringBoot系列(二)入门知识 springBoot系列(三)配 ...

  7. springboot成神之——swagger文档自动生成工具

    本文讲解如何在spring-boot中使用swagger文档自动生成工具 目录结构 说明 依赖 SwaggerConfig 开启api界面 JSR 303注释信息 Swagger核心注释 User T ...

  8. 20190909 SpringBoot集成Swagger

    SpringBoot集成Swagger 1. 引入依赖 // SpringBoot compile('org.springframework.boot:spring-boot-starter-web' ...

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

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

随机推荐

  1. 蒲公英 · JELLY技术周刊 Vol.19 从零开始的 Cloud IDE 开发

    蒲公英 · JELLY技术周刊 Vol.19 你是否也会有想法去开发一个自己的 IDE 却苦于时间和精力不足,完成 Desktop IDE 却又被 Cloud IDE 的概念追在身后难以入睡,这样的两 ...

  2. Java高级特性——反射机制(第三篇)

    获取类运行时的结构 通过反射获取运行时类的完整结构 Field.Method.Constructor.Superclass.Interface.Annotation >实现的全部接口 >所 ...

  3. jmeter http并发测试时报错

    错误信息如下:jmeter Response code: Non HTTP response code: java.net.URISyntaxException 网上收了一大堆,都没法解决 我的用到了 ...

  4. 【HttpRunner v3.x】笔记 ——2. 用脚手架快速创建项目

    环境装好了,相信很多童鞋已经迫不及待的想run起来了,但是面对一个陌生的框架又无从下手.没关系,我们可以用脚手架来快速生成一个httprunner项目. 一.快速生成项目 我们不妨先输入httprun ...

  5. mysql5.7.29- windows64安装教程

    1.配置环境变量 MYSQL_HOME=D:\tools\mysql-5.7. path=%MYSQL_HOME%\bin 2.执行mysqld --initialize-insecure --use ...

  6. NutUI 视频组件开发心得

    引子 说到在项目中引入一个视频,我们肯定会想到 HTML5 为我们提供的 Video 标签,它为我们提供了许多属性和方法,使用起来很方便,当然直接使用也会遇到各种兼容问题,在最初学习 Video 标签 ...

  7. 小程序mpvue中flyio的使用方法

    Fly.js 一个基于Promise的.强大的.支持多种JavaScript运行时的http请求库. 有了它,您可以使用一份http请求代码在浏览器.微信小程序.Weex.Node.React Nat ...

  8. Agumater 增加基本数据上传下载能力

  9. ajax之---上传文件

    “伪”ajax向后台提交文件        <iframe style="display: none" id="iframe1" name="i ...

  10. NGINX 负载均衡的理解

    前言 NGINX是轻量级,也是当前比较流行的web服务器软件.体积小但是功能强大. 这里我按照自己的理解,记录下对NGINX负载均衡的认识.(加权均衡,最小连接) 这里参考了 [https://blo ...