spring boot 中使用swagger
2024-09-06 07:44:01
一、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);
}
最新文章
- 使用KMP算法判断是否为旋转词
- JDK source 之 ArrayList 需要注意事项
- NOIP2015D1
- Sqlite 管理工具收藏
- Java-马士兵设计模式学习笔记-代理模式-动态代理 调用Proxy.newProxyInstance()
- java数据库查询类
- 如何将NTFS格式的移动硬盘挂接到Mac OS上进行读写(Read/Write)操作
- Google Code Jam 2010 Round 1B Problem A. File Fix-it
- 获取布局 ActionBar
- Hibernate框架大配置关联小配置
- ASP.NET连接数据库配置文件
- 快速排序(Quicksort)的Javascript实现
- Vue.js的从入门到放弃进击录(一)
- Open CDN 2.0管控端和节点端安装
- iOS:给标签栏控制器的UITabbarItem添加点击动效
- 【Zookeeper系列】zookeeper面试题(转)
- noip第15课资料
- [wiki]陶德曼调停
- [Object Tracking] Contour Detection through Tensorflow running on smartphone
- vue-cli 3.x脚手架配置并使用vux
热门文章
- 8、Redis五大数据类型---哈希(Hash)
- 攻击科普:ARP攻击
- Linux网络编程入门
- springboot等javaweb项目将jar包安装(打包)到本地Maven仓库
- c++ 之面试题(3)数组递归查找
- 【LeetCode】245. Shortest Word Distance III 解题报告 (C++)
- C. Hongcow Builds A Nation
- 阿克曼函数推导过程(m<;=3)
- 看完这篇 Linux 权限后,通透了!
- Geometric GAN