使用Swagger2 测试接口

  1. Swagger
    是一个规范,完整的框架;用于生成、描述、调用和可视化 RESTful 风格的Web 服务
  2. 相关依赖
    在这里插入图片描述
  3. 配置类
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    
    

    @Bean
    public Docket webApiConfig() {
    
    
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("webApi")
                .apiInfo(webApiInfo())
                .select()
                .paths(Predicates.not(PathSelectors.regex("/admin/.*")))
                .paths(Predicates.not(PathSelectors.regex("/error.*")))
                .build();
    }

    private ApiInfo webApiInfo() {
    
    
        return new ApiInfoBuilder()
                .title("API文档")
                .description("本文档描述了微服务接口定义")
                .version("1.0")
                .contact(new Contact("姓名", "网站",
                        "邮箱"))
                .build();
    }
}
  1. 启动服务,访问Swagger UI
    http://ip:端口号/swagger-ui.html
  2. 当方法参数为List 类型时,参数前加 @RequestParam,Swagger2 测试接口即可输入list (每个元素分行输入)
    在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_51681634/article/details/111135151
今日推荐