swagger2注解使用教程
package com.foen.config;
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.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* @auther: 作者 gzh
* @description: 类说明
* @Date: created in 16:31 2020/5/29
*/
@Configuration
@EnableSwagger2
public class Swagger2 {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())//调用apiInfo方法,创建一个ApiInfo实例,里面是展示在文档页面信息内容
.select()
//控制暴露出去的路径下的实例
//如果某个接口不想暴露,可以使用以下注解
//@ApiIgnore 这样,该接口就不会暴露在 swagger2 的页面下
.apis(RequestHandlerSelectors.basePackage("com.foen.crm.controller"))
.paths(PathSelectors.any())
.build();
}
//构建 api文档的详细信息函数
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
//页面标题
.title("奋安CRM微信小程序说明")
//条款地址
.termsOfServiceUrl("http://despairyoke.github.io/")
.contact("zwd")
.version("1.0")
//描述
.description("奋安CRM接口API 说明,spring boot ,mssql,Swagger2,redis")
.build();
}
}
package com.foen.crm.dto;
import com.foen.sys.enums.RegionEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@Api(tags="文件上传类", value="文件上传类,拍照,扫名片")
@ApiOperation(value = "文件上传",notes = "文件上传",httpMethod = "POST")
@ApiImplicitParam(dataType = "MultipartFile",name = "file",value = "文件对象",required = true)
/**
* https://cloud.tencent.com/document/product/866/36214#.E7.A4.BA.E4.BE.8B1-.E5.90.8D.E7.89.87.E8.AF.86.E5.88.AB.E7.A4.BA.E4.BE.8B.E4.BB.A3.E7.A0.81
* @auther: 作者 gzh
* @description: 类说明
* @Date: created in 15:28 2020/5/21
*/
@ApiModel(description = "名片实体")
public class CardOCRDto {
/**
* 地域: ap-beijing, ap-guangzhou, ap-hongkong, ap-shanghai, na-toronto
*/
@ApiModelProperty(value = "地域")
private String region= RegionEnum.GZ.getValue();
/**
* 图片Base64
*/
@ApiModelProperty(value = "图片Base64")
private String imageBase64;
/**
* 图片地址
*/
@ApiModelProperty(value = "图片地址")
@NotEmpty(message = "用户名不能为空")
@NotNull(message = "用户名不能为Null")
@NotBlank(message = "不能为空格")
private String imageUrl;
/**
* Config
*/
@ApiModelProperty(value = "Config")
private String config;
public String getRegion() {
return region;
}
public void setRegion(String region) {
this.region = region;
}
public String getImageBase64() {
return imageBase64;
}
public void setImageBase64(String imageBase64) {
this.imageBase64 = imageBase64;
}
public String getImageUrl() {
return imageUrl;
}
public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}
public String getConfig() {
return config;
}
public void setConfig(String config) {
this.config = config;
}
}
https://www.jianshu.com/p/f30e0c646c63
@Api(tags="文件上传类", value="文件上传类,拍照,扫名片")
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~