swagger demo code
//Application 开启注解
@EnableSwagger2
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
pom.xml
<!-- Swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
SwaggerConfig.java
package com.qmorn.appapi.config; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket; @Configuration
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.qmorn.appapi.user"))
.paths(PathSelectors.any())
//.apis(RequestHandlerSelectors.any())
//.paths(Predicates.not(PathSelectors.regex("/error.*")))
.build()
.apiInfo(apiInfo());
} private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("对外开放接口API 文档")
//.description("HTTP对外开放接口")
.version("1.0.0")
//.termsOfServiceUrl("http://xxx.xxx.com")
//.license("LICENSE")
//.licenseUrl("http://xxx.xxx.com")
.build();
}
}
SwaggerDemo.java
package com.qmorn.appapi.user; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore; /**
*
* @author YuwenTims
* @Date 2018-06-14
*/ @RestController
public class SwaggerDemo { @ApiOperation(value = "paramType : query", notes = "第一行说明</br>第二行")
@RequestMapping(value = "/byQuery", method = { RequestMethod.POST })
public String byQuery(@RequestParam Integer id) {
return "id = " + id;
} @ApiOperation(value = "paramType : path")
@RequestMapping(value = "/byPath/{id}", method = { RequestMethod.POST })
public String byPath(@PathVariable(name = "id") Long id) {
return "id = " + id;
} @ApiOperation(value = "paramType : header")
@ApiImplicitParams({ @ApiImplicitParam(paramType = "header", dataType = "String", name = "id", value = "参数", required = true) })
@RequestMapping(value = "/byHeader", method = { RequestMethod.POST })
public String byHeader(@RequestHeader ("id") String id) {
return "user id = " + id;
} @ApiOperation(value = "paramType : form")
@ApiImplicitParams({ @ApiImplicitParam(paramType = "form", dataType = "Long", name = "id", value = "参数", required = true) })
@RequestMapping(value = "/byForm", method = { RequestMethod.POST })
public String byForm(@RequestParam(value="id",defaultValue="0") Long id) {
return "user id = " + id;
} @ApiOperation(value = "paramType : body")
@ApiImplicitParams({ @ApiImplicitParam(paramType = "body", dataType = "String", name = "id", value = "参数", required = true) })
@RequestMapping(value = "/queryByBody", method = { RequestMethod.POST })
public String queryByBody(@RequestBody String id) {
return "user id = " + id;
} @ApiIgnore//忽略此接口说明(在swagger-ui文档中不显示)
@RequestMapping(value = "/ignore", method = { RequestMethod.POST })
public String ignore(@RequestParam Long id) {
return "user id = " + id;
}
}
swagger demo code的更多相关文章
- penpyxl basic function demo code
Openpyxl basic function demo code demo code: #!/usr/bin/env python # -*- coding: utf-8 -*- "&qu ...
- RAD Studio Demo Code和几个国外FMX网站 good
FireMonkey X – Amazing overview of FireMonkey FMX Feeds – All your FireMonkey news in one place FMX ...
- SpringBoot + Swagger Demo
Swagger是什么? Swagger 是一个规范且完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务. Swagger 的目标是对 REST API 定义一个标准且和语 ...
- ps2keyboard demo code for 8052
#pragma code symbols debug objectextend #include <reg51.h> /* special function register declar ...
- ( ! ) Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in D:\demo\code\yolo\index\index.php on li
sql语句为:$sql="select count(*) from com where a_id=$v['id']"; 出现以下错误: 原因: 变量没有用花括号引起来 改为: $ ...
- npm install 安装报错:npm ERR! EPERM npm ERR! -4048 npm ERR! Error: EPERM: operation not permitted, unlink 'D:\test\demo\code\materialT\node_modules\.staging'
更新项目依赖包,删除掉package-lock.json.node_modules,运行npm install,报如上错误信息,查询资料说是没有权限,本人用管理员身份打开powershell,运行np ...
- c++ demo code
/* //多继承 #include <iostream> using namespace std; class Sofa { public: Sofa(); ~Sofa(); void s ...
- 使用dropwizard(5)--加入swagger
前言 Swagger已经成API service的规范了,本处在dropwizard中简单集成Swagger. Demo source https://github.com/Ryan-Miao/l4d ...
- Asp.Net Core配置Swagger
本文主要参考:Using Swagger with ASP.net Core 1.创建WebApi项目 本文使用ASP.Net Core Web API项目模板演示Swagger到使用,首先创建Web ...
随机推荐
- 算法Sedgewick第四版-第1章基础-1.4 Analysis of Algorithms-004计算内存
1. 2. 3.字符串
- Luogu 2824 [HEOI2016/TJOI2016]排序
BZOJ 4552 挺妙的解法. 听说这题直接用一个桶能拿到$80 \ pts$ 发现如果是一个排列的话,要对这个序列排序并不好做,但是假如是$01$序列的话,要对一个区间排序还是很简单的. 发现最后 ...
- Person的delete请求--------详细过程
首先,数据库的增删改查都是在PersonRepository中实现,因此,直接进入PersonRepository,找到其父类,搜索delete. @Override @TransactionalMe ...
- C++面试笔记--树
树 树的题目基本都是二叉树,但是面试官还没有说是不是二叉树的时候千万不要先把答案说出来,要是面试官说是多叉树,而你做的是二叉树就直接挂了! 一. 树的三种遍历.前序.中序.后序,如果直接考遍历,就肯定 ...
- 《Maven实战》笔记-2-坐标和依赖
一.依赖范围 Maven在编译项目主代码的时候,需要使用一套classpath——编译classpath: 在编译和执行测试的时候,使用另一套classpath——测试classpath: 实际运行M ...
- 网站下载器WebZip、Httrack及AWWWB.COM网站克隆器
动机 闲扯节点,可略读. 下载并试用这些软件并非是为了一己之私,模仿他人网站以图利.鉴于国内网络环境之艰苦,我等屌丝级半罐水程序员,纵有百度如诸葛大神万般协力相助,也似后主般无能不能解决工作和娱乐中 ...
- 国内物联网平台(3):QQ物联智能硬件开放平台
国内物联网平台(3)——QQ物联·智能硬件开放平台 马智 平台定位 将QQ帐号体系.好友关系链.QQ消息通道及音视频服务等核心能力提供给可穿戴设备.智能家居.智能车载.传统硬件等领域的合作伙伴,实现用 ...
- 改变HTML文件上传控件样式
思路: 1.重写一个新的样式 2.将默认样式设置display:none;,即设为不可见 3.在js里调用:当点击新样式的时候,调用这个input的点击事件 html: <div class=& ...
- 基于vue框架项目开发过程中遇到的问题总结(二)
1.mouseup事件丢失 查看了网上资料,造成mouseup事件丢失有两种原因: (1)触发了浏览器的drag事件 (2)由于鼠标离开了操作的区域,触发了mouseleave事件导致mouseup丢 ...
- Iterator 遍历器
1.遍历器(Iterator)是一种接口,为各种不同的数据结构提供统一的访问机制.任何数据结构只要部署Iterator接口,就可以完成遍历操作(即依次处理该数据结构的所有成员). 2.Iterator ...