springboot搭建swagger2 knife4j

本文介绍了如何在Spring Boot项目中集成Swagger2和Knife4j,包括添加pom依赖,配置yml,创建Swagger2Config,定义DemoController,设计User实体类,枚举类型EnumCode和FileModuleEnum,以及返回结果类Result。
摘要由CSDN通过智能技术生成

1.pom依赖

<!--swagger依赖-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
        <!--<dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>-->
        <!--swagger-bootstrap-ui-->
        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>swagger-bootstrap-ui</artifactId>
            <version>1.9.2</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>knife4j-annotations</artifactId>
            <version>2.0.4</version>
        </dependency>

2.yml配置

##文件上传根路径
upload-file:
  base-path: D:/file/report/
  http-url: http://127.0.0.1:56743/
#swagger公共信息
swagger:
  title: 接口文档系统
  description: 接口文档系统
  version: 2.8.0.RELEASE
  license: Powered By kkp
  license-url:
  terms-of-service-url:
  contact:
    name:
    email:
    url:
#knife4j配置
knife4j:
  #启用
  enable: true
  #基础认证
  basic:
    enable: false
    username: blade
    password: blade

3.Swagger2Config

package com.example.demo1;

import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.ClassUtils;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


/**
 * @author kkp
 * @ClassName Swagger2Config
 * @date 2021/12/6 14:30
 * @Description
 */
@Configuration
@EnableSwagger2
public class Swagger2Config {
   

    @Bean
    public Docket customDocket(){
   
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("业务模块")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.demo1.controller"))
                .paths(PathSelectors.any())
                .build();
    }


    private ApiInfo apiInfo() {
   
        Contact contact 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值