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 ...
随机推荐
- 后台执行UNIX/Linux命令和脚本的五种方法
hiveserver 后台启动 nohup "${HIVE_HOME}"/bin/hive --service hiveserver2 & 1. 使用&符号在后台执 ...
- html5 Web Workers.RP
虽然在JavaScript中有setInterval和setTimeout函数使javaScript看起来好像使多线程执行,单实际上JavaScript使单线程的,一次只能做一件事情(关于JavaSc ...
- Python学习笔记--2--面向对象编程
面向对象 类和装饰器@ #coding=gbk class student: def __init__(self,name,grand):#初始化构造函数,self相当于java中的this,相当于一 ...
- Web Api 测试工具
1.调用POST方法:使用Chrome流量器的PostMan工具. 前端模拟发送数据/调试的好工具:Chrome下的Postman-REST Client 下载地址 https://chrome.go ...
- C# console application executing macro function
C#控制台应用程序,执行或运行Office的宏函数,程序如下: 应用例子:
- eclise远程调试
配置很简单,如下: 1. tomcat在bin/catalina.sh中添加如下:declare -x CATALINA_OPTS="-server -Xdebug -Xnoagent -D ...
- fseek函数
函数名:fseek函数 头文件:#include<stdio.h> 功能:把与fp有关的文件位置指针放到一个指定位置. 格式: int fseek(FILE *stream, long ...
- jzoj4915. 【GDOI2017模拟12.9】最长不下降子序列 (数列)
题面 题解 调了好几个小时啊--话说我考试的时候脑子里到底在想啥-- 首先,这个数列肯定是有循环节的,而且循环节的长度\(T\)不会超过\(D\) 那么就可以把数列分成三份,\(L+S+R\),其中\ ...
- 适配器设计模式初探(Java实现)
本篇随笔主要介绍Java实现设配器设计模式. 先来看下待解决的问题: (图片转自http://blog.csdn.net/jason0539) 由上图的情况可知,欧洲壁式插座只有三足插口,如果我们想要 ...
- 「FJ2014集训」采药人的路径
啦啦啦 来写一篇题解 洛谷链接: P4930 「FJ2014集训」采药人的路径 统计路径?嗯往点分治上想. 把0和1转化为-1和1,求和完dis为0的路径就是阴阳平衡的路径了. 如果题目没有限制要有中 ...