要在Spring Boot项目中集成Swagger文档,可以按照以下步骤操作:
添加Swagger依赖:在项目的pom.xml文件中添加Swagger的依赖:<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-boot-starter</artifactId> <version>3.0.0</version></dependency>创建Swagger配置类:在项目中创建一个Swagger配置类,用于配置Swagger的相关信息,例如文档标题、描述、版本等。示例代码如下:@Configurationpublic class SwaggerConfig { @Bean public Docket api() { return new Docket(DocumentationType.OAS_30) .select() .apis(RequestHandlerSelectors.basePackage("com.example.controller")) .paths(PathSelectors.any()) .build() .apiInfo(apiInfo()); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("API Documentation") .description("Swagger documentation for API endpoints") .version("1.0") .build(); }}启用Swagger:在Spring Boot的启动类上使用@EnableSwagger2注解来启用Swagger:@SpringBootApplication@EnableSwagger2public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); }}访问Swagger文档:启动Spring Boot应用程序后,可以通过访问http://localhost:8080/swagger-ui/来查看生成的Swagger文档界面,其中包含了API的各个接口和相关信息。通过以上步骤,就可以在Spring Boot项目中集成Swagger文档并查看API接口的详细信息。




