引入依赖
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>2.0.8</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-core</artifactId>
<version>3.0.0</version>
<scope>compile</scope>
</dependency>
配置类SwaggerConfig
package com.ruoyi.hsoutinterface.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
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.EnableSwagger2WebMvc;
@Configuration
@EnableSwagger2WebMvc
public class SwaggerConfig {
@Value("${swagger.enabled}")
private boolean enable = true;
@Bean(value = "api")
public Docket defaultApi2() {
Docket docket=new Docket(DocumentationType.SWAGGER_2)
.enable(enable)
.apiInfo(apiInfo())
//分组名称
.groupName("hs1.X版本")
.select()
//这里指定Controller扫描包路径
.apis(RequestHandlerSelectors.basePackage("com.ruoyi.web.controller.hsoutinterface"))
.paths(PathSelectors.any())
.build();
return docket;
}
/**
* @Description: 构建 api文档的信息
*/
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
// 设置页面标题
.title("恒实信用对外接口文档")
// 设置联系人
.contact(new Contact("fengqing", "https://www.abc.com/","888888@qq.com"))
// 描述
.description("controller层接口如下")
// 定义版本号
.version("1.0").build();
}
}
实体类的注解和swagger2的一样
package com.ruoyi.hsoutinterface.domain;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
/**
* @author luheng
* @date 2024-03-25
*/
@ApiModel(value = "个人信息")
public class Vatarrears
{
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "主键", example = "测试值")
private String fId;
@ApiModelProperty(value = "企业信用代码", example = "测试值")
private String taxpayerId;
}
浏览器访问接口文档