Idea创建swagger项目步骤详解

一、搭建项目

  1. 打开Idea,点击【File】-【New】-【Project...】-【Spring Initializr】-点击【Next】-【Next】

  2. 在添加依赖的页面,点击【Web】-勾选【Web】-【Next】-【Finish】。项目即创建成功。(中途可自行修改项目名称等)

二、添加依赖

    1.打开pom.xml文件,添加swagger的两个依赖。

<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>

三、Swagger配置类

   1.在项目目录下创建包“config”,并添加配置类SwaggerConfig.java,内容如下:

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket applicationApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("fakerswe")
                .select()  // 选择哪些路径和api会生成document
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any()) // 对所有路径进行监控
                .build()
                .apiInfo(applicationInfo());//用来创建该Api的基本信息(这些基本信息会展现在文档页面中)
    }

    private ApiInfo applicationInfo() {
        ApiInfo apiInfo = new ApiInfo("接口管理",//大标题
                "api接口可视化管理" ,//小标题
                "0.1",//版本
                "",
                new Contact("叶湘伦", "", ""),// 作者
                "",//链接显示文字
                ""//网站链接
        );
        return apiInfo;
    }
}

    

    2.扫描启动类-DemoApplication.java

@SpringBootApplication
@ComponentScan("com.*")//此处需进行扫描
public class DemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值