springboot整合knife4j

knife4j是为Java MVC框架集成Swagger生成Api文档的增强解决方案,前身是swagger-bootstrap-ui,前身swagger-bootstrap-ui是一个纯swagger-uiui皮肤项目,取名knife4j是希望它能像一把匕首一样小巧,轻量,并且功能强悍!其底层是对Springfox的封装,使用方式也和Springfox一致,只是对接口文档UI进行了优化。

官网:Knife4j · 集Swagger2及OpenAPI3为一体的增强解决方案. | Knife4j

1、导入相关包

<!--官网建议:Spring Boot 版本建议 2.4.0~3.0.0之间-->
        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>knife4j-openapi2-spring-boot-starter</artifactId>
            <version>${knife4j-spring.version}</version>
        </dependency>

2、在application.yml配置文件中,添加knife4j相关的配置信息

# Knife4j文档
knife4j:
  enable: true
  basic:
    enable: false
    username: admin
    password: admin
  openapi:
    title: 在线文档
    description: "Knife4j文档"
    # aaa"
    email: xiaoymin@foxmail.com
    concat: xxx
    url: https://www.xxxx.com/
    version: v4.0
    license: Apache 2.0
    group:
      test1:
        group-name: 分组名称
        api-rule: package
        api-rule-resources:
          - com.xxx.xx.controller

3、在controller层添加相应的文档注释

@Api(tags = "首页模块")
@ApiOperation(value = "首页信息")
@Api(tags = "首页模块")
@RestController
public class IndexController {

    @ApiOperation(value = "首页信息")
    @GetMapping
    public String index(){
        return "security chapter 02 前后分离";
    }
}

显示效果:http://localhost:8080/doc.html

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值