java spring boot Swagger接口管理

第一:在pom.xml引入swagger的jar包如下:

<dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.6.1</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.6.1</version>
        </dependency>

第二:在应用启动器类同级下创建一个SwaggerConfig类如下:

package com.boot.dp;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
public class SwaggerConfig {

      @Bean --如果有多个controller文件夹 可以编写多个该方法即可(注意:方法名不能相同)
      public Docket SystemBaseApi() {
        return new Docket(DocumentationType.SWAGGER_2)
            .groupName("某某模块API接口文档")
            .apiInfo(apiInfo())
            .select()
             //为当前包路径
            .apis(RequestHandlerSelectors.basePackage("com.boot.dp.modules.base.controller"))
            .paths(PathSelectors.any())
            .build();
      }
      private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
            //页面标题
            .title("项目标题")
             //创建人
            .contact(new Contact("创建人名称", "网址", "邮件"))
            //描述
            .description("模块controller类描述")
            //版本号
            .version("1.0")
            .build();
      }
    }

第三:在某个controller文件包下某个controller方法编写相应的api接口描述说明和传参数个数和方法类型等如下:

/**
     * 列表
     * @param params
     * @return
     */
    @ApiOperation(value="某个模块下某个菜单-列表",notes="在swagger页面上某个controller方法描述")
    @ApiImplicitParam(name="参数名称",value="参数所需要输入值",required=true,dataType="参数类型格式")
    @RequestMapping(value="/方法名",method=接收方法类型(get或psot))
    public Page<BsCustomerEntity> list(@RequestBody Map<String, Object> params) {
        return bsCustomerService.listBsCustomer(params);
    }

第四:最后在系统添加一个访问api接口连接如下:

http://localhost:8080/index.html#swagger-ui.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值