springboot项目整合Swagger2
【摘要】 项目整合 swagger
在聚合工程中的父 pom 工程的 pom 文件中添加依赖
<!-- swagger2 配置 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactI...
项目整合 swagger
在聚合工程中的父 pom 工程的 pom 文件中添加依赖
<!-- swagger2 配置 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.6</version>
</dependency>
- 指定API类型为swagger2.0
- 定义API文档汇总信息
- 指定controller包
- 所有controller
源码解析
package springfox.documentation.spi;
import org.springframework.http.MediaType;
import org.springframework.plugin.metadata.SimplePluginMetadata;
public class DocumentationType extends SimplePluginMetadata {
public static final DocumentationType SWAGGER_12 = new DocumentationType("swagger", "1.2");
public static final DocumentationType SWAGGER_2 = new DocumentationType("swagger", "2.0");
public static final DocumentationType SPRING_WEB = new DocumentationType("spring-web", "1.0");
private final MediaType mediaType; /** * Creates a new instance of {@code SimplePluginMetadata}. */
public DocumentationType(String name, String version, MediaType mediaType) { super(name, version); this.mediaType = mediaType;
} public DocumentationType(String name, String version) { this(name, version, MediaType.APPLICATION_JSON);
} public MediaType getMediaType() { return mediaType;
} @Override
public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof DocumentationType)) { return false; } if (!super.equals(o)) { return false; } DocumentationType that = (DocumentationType) o; return super.equals(that) && mediaType.equals(that.mediaType); } @Override
public int hashCode() { int result = super.hashCode(); result = 31 * result + mediaType.hashCode(); return result;
}
}
Swagger JSON Doc
- 在线编辑地址
https://editor.swagger.io/ - 编辑生成样板代码
所以 swagger 不仅支持代码优先还支持契约优先编程。
文章来源: javaedge.blog.csdn.net,作者:JavaEdge.,版权归原作者所有,如需转载,请联系作者。
原文链接:javaedge.blog.csdn.net/article/details/105852392
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
作者其他文章
评论(0)