springboot3集成Swagger3

一、引入Swagger3的依赖

       <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>

二、Swagger3的配置

package com.wzy.test.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


@Configuration
@EnableSwagger2 //swagger3版本不需要使用这个注解,当然写上也无所谓~
public class Swagger3Config {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.OAS_30)  // swagger2版本这里是DocumentationType.SWAGGER_2
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("XXXX管理平台")
                .description("XXXX管理平台 API接口文档")
                .license("小魏学习啦") //随便写个某公司都行
                .licenseUrl("www.xiaowei.com") // 可以写个某某网址
                .version("1.0")
                .build();
    }
}

三、由于MVC冲突可能出问题,在配置类加上@EnableWebMvc注解

b89f0dae9217403fb459146c547212de.png

四、设置完毕打开网址

http://localhost:端口号/swagger-ui/index.htmlhttp://localhost/swagger-ui/index.html

http://localhost:端口号/swagger-ui/index.html

五、Swagger提供的注解

1.@ApiModel(value = "XXX数据库名称的对象")--->一般用在实体类的类上

94c3755a40f8468a965d2d6933126a5f.png

2.@ApiModelProperty("意思")-------->一般用在数据库字段上用

2f4c728019e14e3b9f784c14d3fc0b24.png

3.@Api(tags = "") 一般用在Controller的类上

74394b9fe74e43598157123cc3f14e75.png

4.@ApiOperation(" ")  用在Controller的方法上

11ccf94fe224484fb349f282b39bf327.png

 

  • 6
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
SpringBoot 3集成Swagger 3的步骤如下: 1. 首先,需要在项目的pom.xml文件中添加SpringFox的依赖项。可以使用以下代码片段添加依赖项: ``` <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-boot-starter</artifactId> <version>3.0.0</version> </dependency> ``` 这将帮助将Swagger 3集成Spring中。 2. 在控制器类上添加@Api注解,用于定义Swagger页面的信息。例如: ``` @RestController @RequestMapping("/user") @Api(tags = "人员信息查询接口") public class UserController { // ... } ``` 这将在Swagger页面上显示"人员信息查询接口"标签。 3. 在需要生成API文档的方法上添加@ApiOperation注解,用于定义方法的说明。例如: ``` @GetMapping("/queryPage") @ApiOperation(value = "人员信息分页查询方法", notes = "查看人员信息是否返回成功") public Result queryPage(Integer pageNumber, Integer pageSize, String name) { // ... } ``` 这将在Swagger页面上显示"人员信息分页查询方法"的说明。 4. 最后,根据需要进行其他配置。例如,如果需要修改SpringBoot的路径匹配模式,可以在application.yml文件中进行配置。例如: ``` spring: mvc: pathmatch: matching-strategy: ANT_PATH_MATCHER ``` 这将使用AntPathMatcher作为路径匹配策略。 综上所述,以上是SpringBoot 3集成Swagger 3的基本步骤和配置。通过这些步骤,您可以在SpringBoot项目中使用Swagger来生成API文档。 #### 引用[.reference_title] - *1* *3* [SpringBoot整合Swagger3.0](https://blog.csdn.net/weixin_43709291/article/details/127192273)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Springboot项目集成Swagger3.0](https://blog.csdn.net/weixin_44924882/article/details/127940544)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值