//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的更多相关文章

  1. penpyxl basic function demo code

    Openpyxl basic function demo code demo code: #!/usr/bin/env python # -*- coding: utf-8 -*- "&qu ...

  2. RAD Studio Demo Code和几个国外FMX网站 good

    FireMonkey X –  Amazing overview of FireMonkey FMX Feeds – All your FireMonkey news in one place FMX ...

  3. SpringBoot + Swagger Demo

    Swagger是什么? Swagger 是一个规范且完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.  Swagger 的目标是对 REST API 定义一个标准且和语 ...

  4. ps2keyboard demo code for 8052

    #pragma code symbols debug objectextend #include <reg51.h> /* special function register declar ...

  5. ( ! ) 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']"; 出现以下错误: 原因: 变量没有用花括号引起来 改为:  $ ...

  6. 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 ...

  7. c++ demo code

    /* //多继承 #include <iostream> using namespace std; class Sofa { public: Sofa(); ~Sofa(); void s ...

  8. 使用dropwizard(5)--加入swagger

    前言 Swagger已经成API service的规范了,本处在dropwizard中简单集成Swagger. Demo source https://github.com/Ryan-Miao/l4d ...

  9. Asp.Net Core配置Swagger

    本文主要参考:Using Swagger with ASP.net Core 1.创建WebApi项目 本文使用ASP.Net Core Web API项目模板演示Swagger到使用,首先创建Web ...

随机推荐

  1. 异常日志记录 DDLog

    项目中如果想把异常捕获再写入文件,有个十分容易使用的库DDLog. 首先导入库,在git上下载. 一:在项目初始化指定全局LogLeve ,一般在xxxapp.m中 staticconstint dd ...

  2. ARC061E Snuke's Subway Trip

    传送门 题目大意 已知某城市的地铁网由一些地铁线路构成,每一条地铁线路由某一个公司运营,该城市规定:若乘坐同一公司的地铁,从开始到换乘只需要一块钱,换乘其他公司的价格也是一块钱,问从1号地铁站到n号地 ...

  3. Bootstrap 的 Modal

    一.简介 Modal 就是弹出框,这里 有一个例子. Modal 的完整代码如下: <div class="modal fade" tabindex="-1&quo ...

  4. layui下select下拉框不显示或没有效果

    Layui会对select.checkbox.radio等原始元素隐藏,从而进行美化修饰处理.但这需要依赖于form组件,所以你必须加载 form,并且执行一个实例.值得注意的是:导航的Hover效果 ...

  5. NSString 字符串

    0.字符串常用操作 自动补充方法:当字符串长度不够需要自动补充到一定的位数 OC字符串与C语言字符串之间的相互转换 1.不可变字符串的创建 // 直接创建不可变字符串 /* 在 OC 中,使用 @&q ...

  6. 818. Race Car

    Your car starts at position 0 and speed +1 on an infinite number line.  (Your car can go into negati ...

  7. ASP.NET-GridView之导出excel或word

    在CS阶段我们涉及到表格的导出,再Web开发同样可以实现,而且实现形式多种多样.以下面的例子说明表格导出到excel和word 这里用到了一个后台方法输出流形成***文件的的公共方法 DEMO < ...

  8. Java整体之JavaEE

    思维导图 (Xmind)链接:http://pan.baidu.com/s/1pKTOTRH 密码:oq7f <iframe src="http://www.xmind.net/emb ...

  9. C/C++ 遇到0xcccccccc访问冲突

    最近一直在纠结这个问题. 最近写代码,总是遇到这个问题,一旦遇到这个问题,以前好使的代码也就不好使了.很费解,上网搜集了下资料.... 这个0xcccccccc是DEBUG模式下,编译器为没有初始化的 ...

  10. [Swift实际操作]九、完整实例-(6)创建App欢迎界面

    本文创建一个位于导航控制器之内的欢迎页面,该页面主要用来向用户简要介绍产品的功能.以及提供主要功能的入口. 首先选择自定义视图文件夹[CustomViews],需要在该文件夹下,导入一款第三方类库.该 ...