1:导入依赖
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-boot-starter --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-boot-starter</artifactId> <version>3.0.0</version> </dependency>
2:添加配置
package com.example.demo.demos.web.swaggeapi; import org.springframework.context.annotation.Configuration; @Configuration public class swaggerConfig { }
3:启动类加开关注解@EnableOpenApi
作用:表示开启生成接口文档功能,只有开启了OpenApi,才能实现生成接口文档的功能
@SpringBootApplication @EnableOpenApi public class Demo1Application { public static void main(String[] args) { SpringApplication.run(Demo1Application.class, args); } }
4:访问页面
默认端口号是8080,各位根据实际情况修改即可:http://localhost:8080/swagger-ui/index.html