前后端分离-利用Swagger生成接口文档

本文介绍了如何利用Swagger来生成接口文档,详细讲解了Swagger的配置步骤,包括在pom.xml中添加依赖,配置Swagger及WebMvc。通过编写简单的接口,并访问http://localhost:8080/swagger-ui.html#/查看生成的接口文档效果。源码可在文章末尾获取。
摘要由CSDN通过智能技术生成

相关介绍(Swagger)

  • Swagger官网

  • 是一款让你更好的书写API文档的规范且完整框架。

  • 提供描述、生产、消费和可视化RESTful Web Service。

  • 是由庞大工具集合支撑的形式化规范。这个集合涵盖了从终端用户接口、底层代码库到商业API管理的方方面面。

配置过程

源码见文章尾

pom.xml

<!--swagger-api依赖开始-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.7.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.7.0</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.8</version>
        </dependency>
        <!--swagger-api结束-->

配置Swagger

@Component
@EnableSwagger2
@EnableWebMvc  //必须存在
//必须存在,扫描的API Controller包
@ComponentScan(basePackages = {
   "com.swagger.controller"})
public class SwaggerConfig {
   
    @Bean
    public Docket customDocket(){
   return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo());}

    private ApiInfo apiInfo(){
   
        Contact contact = new Contact("GodF","https://www.baidu.com","1234567@qq.com")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值