首页 > 其他分享 >Swagger的基本使用

Swagger的基本使用

时间:2022-11-18 18:11:22浏览次数:30  
标签:基本 实体类 value controller 使用 new Swagger 讲师

  1. 添加一个配置类SwaggerConfig.java
@Configuration
@EnableSwagger2 //开启Swagger
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("Helen", "http://atguigu.com", "[email protected]"))
                .build();
    }
}

  1. 启动项目,访问url:http://localhost:8001/swagger-ui.html
  2. 常用注解
//用在controller上说明该controller的作用
@Api(description = "讲师管理")
//用在controller的方法上,用于说明方法的作用
@ApiOperation(value = "讲师列表")
//用于参数的上,参数的说明
@ApiParam(name = "id", value = "讲师ID")
//用在实体类上,对实体类的描述
@ApiModel(value="EduTeacher对象", description="讲师")
//用在实体类的字段上,对字段的描述
@ApiModelProperty(value = "讲师ID")

标签:基本,实体类,value,controller,使用,new,Swagger,讲师
From: https://www.cnblogs.com/blog-zyx/p/16904139.html

相关文章