一、pom.xml

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>

二、创建Swagger2类
@Configuration
@EnableSwagger2
public class Swagger2 {
@Bean
public Docket createRestApi() {
List<Parameter> pars = new ArrayList<Parameter>();
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
.paths(PathSelectors.any())
.build()
.globalOperationParameters(pars)
.apiInfo(apiInfo());
}

private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("小王 RESTful API")
.description("使用swagger2结合写api")
.termsOfServiceUrl("https://www.cnblogs.com/")
.version("1.0")
.build();
}
}
三、启动位置配置
@SpringBootApplication
@EnableSwagger2
public class SmlzApplication {

public static void main(String[] args) {
SpringApplication.run(SmlzApplication.class, args);
}
}
四、使用
@PostMapping("/save-book")
@ApiOperation(value = "添加书籍",notes = "暂时没连接数据库")
public Book saveBook(@RequestBody Book book){
return bookSerivce.insertByBook(book);
}


最新文章

  1. 使用KMP算法判断是否为旋转词
  2. JDK source 之 ArrayList 需要注意事项
  3. NOIP2015D1
  4. Sqlite 管理工具收藏
  5. Java-马士兵设计模式学习笔记-代理模式-动态代理 调用Proxy.newProxyInstance()
  6. java数据库查询类
  7. 如何将NTFS格式的移动硬盘挂接到Mac OS上进行读写(Read/Write)操作
  8. Google Code Jam 2010 Round 1B Problem A. File Fix-it
  9. 获取布局 ActionBar
  10. Hibernate框架大配置关联小配置
  11. ASP.NET连接数据库配置文件
  12. 快速排序(Quicksort)的Javascript实现
  13. Vue.js的从入门到放弃进击录(一)
  14. Open CDN 2.0管控端和节点端安装
  15. iOS:给标签栏控制器的UITabbarItem添加点击动效
  16. 【Zookeeper系列】zookeeper面试题(转)
  17. noip第15课资料
  18. [wiki]陶德曼调停
  19. [Object Tracking] Contour Detection through Tensorflow running on smartphone
  20. vue-cli 3.x脚手架配置并使用vux

热门文章

  1. 8、Redis五大数据类型---哈希(Hash)
  2. 攻击科普:ARP攻击
  3. Linux网络编程入门
  4. springboot等javaweb项目将jar包安装(打包)到本地Maven仓库
  5. c++ 之面试题(3)数组递归查找
  6. 【LeetCode】245. Shortest Word Distance III 解题报告 (C++)
  7. C. Hongcow Builds A Nation
  8. 阿克曼函数推导过程(m&lt;=3)
  9. 看完这篇 Linux 权限后,通透了!
  10. Geometric GAN