SpringBoot结合swagger2快速生成简单的接口文档

本文档介绍了如何在SpringBoot项目中结合Swagger2快速生成接口文档。主要步骤包括在pom.xml添加依赖,启动类启用@EnableSwagger2Doc注解,以及在application.properties中的基本配置。值得注意的是,即使不配置application.properties,Swagger2也能生成并测试接口文档。如需了解更多详情,可访问作者的个人网站。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. pom.xml中加入依赖
        <dependency>
            <groupId>com.spring4all</groupId>
            <artifactId>swagger-spring-boot-starter</artifactId>
            <version>1.8.0.RELEASE</version>
        </dependency>
2. 在启动类(即带@SpringBootApplication这个注解的类)上添加@EnableSwagger2Doc注解
3. 在application.properties中配置如下
swagger.enabled=true
swagger.title=spring-boot-mybatis module api
swagger.description=Starter for swagger 2.x
swagger.license=Apache License, Version 2.0
swagger.licenseUrl=https://www.apache.org/licenses/LICENSE-2.0.html
swagger.termsOfServiceUrl=https://github.com/pbw123/spring-boot-demo
swagger.contact.name=mqXu
swagger.contact.url=https://www.jianshu.com/u/2f60beddf923
swagger.contact.email=2635225112@qq.com
swagger.base-package=com.springboot.mybatis.controller
swagger.base-path=/**
swagger.exclude-path=/error, /ops/**

经我多次尝试application.properties中不加任何swagger配置也可生成文档进行正常测试


另一种用swagger自动生成文档的方式请前往

个人网站

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值