1. pom

        <!-- swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-ui</artifactId>
<version>2.0.2</version>
</dependency>

2. 代码配置

@Configuration
@EnableSwagger2
public class SwaggerConfig { @Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).apiInfo(createApiInfo())
.select().apis(RequestHandlerSelectors
.basePackage("com.demo.controller")) // 对应项目的controller目录
.paths(PathSelectors.any())
.build();
} private ApiInfo createApiInfo() {
return new ApiInfoBuilder()
.title("主题")
.description("描述信息")
.termsOfServiceUrl("http://localhost")
.version("1.0.0")
.contact(new Contact("张叔叔", "http://localhost", "email@com"))
.build();
}
}

3. controller中添加 swagger注解

@Slf4j
@Api("用户控制器")
@RestController
@RequestMapping(value = "/api/v1/demo_one/user", produces = "application/json")
public class UserController implements DemoOneService { @RequestMapping(value = "/say", method = RequestMethod.GET)
public String hello(@RequestParam("name") String name) {
return "Hello " + name;
}
}

4. 登录swagger的ui界面查看在线API信息

  http://localhost:port/swagger-ui.html

  http://localhost:port/doc.html#

Spring Boot --- Swagger基本使用的更多相关文章

  1. spring boot + swagger + mysql + maven

    1.首先编写 yaml 文件,创建项目所需的接口,在swagger.io官网上生成 spring boot项目: 2.由于生成的spring boot项目是公共类的所以还需要修改成所需的项目名称,主要 ...

  2. spring boot Swagger 集成

    1. pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://ww ...

  3. Spring Boot : Swagger 2

    每次修改完代码需要找原本的API时楼主的内心是痛苦的,因为一般情况下都找不到,需要重新写一份.如果使用Swagger的话,只要加几个注解就可以实时生成最新的在线API文档,而且不仅仅是文档,同时支持A ...

  4. Spring Boot + Swagger

    前言: 在互联网公司, 微服务的使用者一般分为两种, 客户端和其他后端项目(包括关联微服务),不管是那方对外提供文档 让别人理解接口 都是必不可少的.传统项目中一般使用wiki或者文档, 修改繁琐,调 ...

  5. Spring Boot 集成Swagger

    Spring Boot 集成Swagger - 小单的博客专栏 - CSDN博客https://blog.csdn.net/catoop/article/details/50668896 Spring ...

  6. Spring Boot项目简单上手+swagger配置+项目发布(可能是史上最详细的)

    Spring Boot项目简单上手+swagger配置 1.项目实践 项目结构图 项目整体分为四部分:1.source code 2.sql-mapper 3.application.properti ...

  7. HTTP RESTful服务开发 spring boot+Maven +Swagger

    这周配合第三方平台整合系统,需要提供HTTP REST服务和使用ActiveMQ推送消息,研究了下,做个笔记. 1.使用eclipse创建Spring Boot项目  创建Spring Boot项目( ...

  8. spring boot swagger-ui.html 404

    很奇怪的问题,找了好久. 因为spring boot+swagger实现起来很简单.看下面三部曲: 1.pom添加两个swagger依赖. <!-- Swagger依赖包 --> < ...

  9. Spring boot中使用springfox来生成Swagger Specification小结

    Rest接口对应Swagger Specification路径获取办法: 根据location的值获取api   json描述文件 也许有同学会问,为什么搞的这么麻烦,api json描述文件不就是h ...

随机推荐

  1. AR涂涂乐

    <1> 涂涂乐着色 https://blog.csdn.net/begonia__z/article/details/51282932 http://www.manew.com/blog- ...

  2. python学习笔记(七)- 递归、python内置函数、random模块

    1.函数的不固定参数: #参数不是必填的.没有限制参数的个数.返回参数组的元组 def syz(*args): #参数组,不限制参数个数 #‘args’参数的名字可以随便命名 print(args) ...

  3. cdnbest站点里设置防盗链

    设置需求只允许 test.kangleweb.com 访问  ,其他网站链接全部拒绝 (注:如果test.kangleweb.com是用https访问,那引用的内容地址www447.yivpn.cn也 ...

  4. 735. Asteroid Collision彗星相撞后的消失数组

    [抄题]: We are given an array asteroids of integers representing asteroids in a row. For each asteroid ...

  5. python基础(二)列表与字典

    列表list-数组stus=['苹果','香蕉','橘子','红枣',111.122,]# 下标 0 1 2 3 4#下标,索引,角标#print(stus[4]) #st=[]#空list#st=l ...

  6. ios tableView的header高度不对

    tableView的header高度不对,一般都是header是从xib加载出来的 第一步: 新建xib的时候选择的是View,当选择 Size 为 Freeform 时,view的约束就变成这样了, ...

  7. python小练习:使用循环和函数实现一个摇骰子小游戏。游戏规则如下:游戏开始,首先玩家选择Big or Small(押大小),选择完成后开始摇三个骰子,计算总值,11<=总值<=18为“大”,3<=总值<=10为“小”。然后告诉玩家猜对或者是猜错的结果。

    python小练习:使用循环和函数实现一个摇骰子小游戏.游戏规则如下:游戏开始,首先玩家选择Big or Small(押大小),选择完成后开始摇三个骰子,计算总值,11<=总值<=18为“ ...

  8. mysql数据库指定ip远程访问 指定用户 指定数据库

    .登录 mysql -u root -p 之后输入密码进行登陆 .权限设置及说明 .1添加远程ip访问权限 GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168 ...

  9. BeanUtils.copyProperties的简单示例

    一.新建测试实体 1.UserA package com.dechy.hebswj.test; public class UserA { private String a; private Strin ...

  10. 三次样条插值算法C++实现

    三次样条插值算法 1 总体说明 三次样条插值算法是一种计算量和效果都比较理想的插值算法.关于三次样条插值算法的原理这里不做过多的解释,下面的代码是我在网上收集了两种C++实现版本的基础上自己整合的一个 ...