SpringBoot 集成Swagger 自动生成API文档

本文介绍如何在SpringBoot项目中集成Swagger,实现API文档自动化生成。通过注解详细描述接口、方法、参数及返回信息,简化前后端沟通,提升测试效率。提供了源码链接和参考文章。
摘要由CSDN通过智能技术生成

swagger用于定义API文档。

源码地址:

https://github.com/tanzj520/SwaggerApiDemo

好处:

  1. 前后端分离开发 API文档非常明确
  2. 测试的时候不需要再使用URL输入浏览器的方式来访问Controller
  3. 传统的输入URL的测试方式对于post请求的传参比较麻烦

其实也可以选择第三方工具 https://www.eolinker.com/

首先,在项目pom中引入依赖,如下(我使用的2.8.0版本)

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

<dependency>
	<groupId>io.springfox</groupId>
	<artifactId>springfox-swagger-ui</artifactId>
	<version>2.8.0</version>
</dependency>
接着,在SpringBoot中创建Application.java,如下(我这里使用的外置tomcat  并没有使用spring boot自带的)
package com.ktnw.management;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@SpringBootApplication //spring boot 应用
@EnableTransactionManagement //事务管理
@EnableSwagger2 //swagger 注解
public class SwaggerApiDemoApplication extends SpringBootServletInitializer {

	@Override
	protected SpringApplicationBuilder con
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值