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="文件上传类,拍照,扫名片")
原文地址:https://www.cnblogs.com/gzhbk/p/12988597.html