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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2021-04-03 我要评论

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自动生成文档的方式请前往

您可能感兴趣的文章:

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们