首页>代码>Swagger的简单案例,适合初级者学习使用>/SwaggerTest/src/main/java/cn/jbit/config/SwaggerConfig.java
package cn.jbit.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
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;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
@EnableKnife4j
public class SwaggerConfig {

    //编写api文档汇总信息
    private ApiInfo apiInfo(){
        return  new ApiInfoBuilder()
                //编写文档标题
                .title("用户消息管理系统接口文档")
                //文档描述
                .description("初次使用swagger的小demo")
                //联系人
                .contact(new Contact("G2",null,"1623502245@qq.com"))
                //文档版本
                .version("1.0")
                .build();
    }


    @Bean
    public Docket createRestApi(){
        //选择swagger2版本
        return  new Docket(DocumentationType.SWAGGER_2)
                //定义api文档汇总信息
                .apiInfo(apiInfo())
                .select()
                //指定生成api文档的包
                .apis(RequestHandlerSelectors.basePackage("cn.jbit"))
                //指定所有路径
                .paths(PathSelectors.any())
                .build();
    }



}
最近下载更多
微信网友_6368711690080256  LV3 2023年2月28日
1203174100  LV1 2023年2月22日
282363  LV1 2022年10月4日
cao1992  LV24 2022年7月18日
yijie110  LV5 2022年4月18日
gy12345  LV6 2022年2月15日
taskmaster  LV6 2022年1月2日
zcl02036716  LV17 2021年12月3日
123854216  LV5 2021年11月24日
hyz419  LV6 2021年9月18日
最近浏览更多
内心向阳  LV4 2023年11月7日
jiemomo  LV12 2023年10月19日
lingtiejing  LV15 2023年10月1日
siximu912  LV10 2023年9月19日
qq573914838  LV5 2023年9月2日
youwuzuichen  LV10 2023年8月14日
空心菜4  LV9 2023年7月16日
8376x123 2023年6月12日
暂无贡献等级
hwbhome 2023年6月4日
暂无贡献等级
wangyz  LV8 2023年5月17日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友