swagger的使用

引入两依赖

<!--    swagger核心-->
    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-swagger2</artifactId>
      <version>2.9.2</version>
    </dependency>
<!--    swagger的ui界面,前缀/swagger-ui.html-->
    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-swagger-ui</artifactId>
      <version>2.9.2</version>
    </dependency>

<!--    bootstrap的swagger-ui界面,前缀/doc.html-->

<dependency>
    <groupId>com.github.xiaoymin</groupId>
    <artifactId>swagger-bootstrap-ui</artifactId>
    <version>1.9.6</version>
</dependency>

启动类加上@EnableSwagger2注解

springboot2.6以上url查找规则改了 

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

添加配置类自定义ui界面信息

@Configuration
public class SwaggerConfig{
    @Bean
    public Docket docket(){
        Docket docket = new Docket(DocumentationType.SWAGGER_2);
        ApiInfo apiInfo = new ApiInfoBuilder()
                .title("动力节点金融项目")
                .version("1.0")
                .description("前后端分离项目,前端Vue,后端SpringBoot+Dubbo分布式项目")
                .contact(new Contact("动力bj2114班级", "https://www.baidu.com/", "wangli7324@qq.com"))
                .license("Apache 2.0")
                .build();
        docket = docket.apiInfo(apiInfo);
        return docket;
    }

}
@RestController
@Api(tags = "hello控制器")//默认controller名称
public class MyController {
    @ApiOperation(value = "输出Swagger的功能", notes = "控制器第一个方法")//默认输出方法名
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "用户姓名", required = true, defaultValue = "zhangsan",
                    dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "id", value = "用户主键", required = true, defaultValue = "12",
                    dataType ="int",paramType="query")
    })
    @GetMapping("/hello")
    public String helloSwagger(String name, Integer id) {
        return "Swagger在线生成接口文档,同时具有测试接口的功能";
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值