@ApiModelProperty的使用

配合Knife4j或Sawgger使用

        
        
        
            com.github.xiaoymin
            knife4j-spring-boot-starter
            ${knife4j.version}
        
        

@ApiModelProperty一般用于给入参属性添加说明时使用:
value:字段说明
name:重写属性名字
dataType:重写属性类型
required:是否必填(true为必填)
example:举例说明
hidden:隐藏(true为隐藏)
allowableValues:允许此参数存储的长度
access:允许从API文档中过滤属性
position:允许显式地对模型中的属性排序(int类型,默认为0)
readOnly:是否允许将属性指定为只读(默认为false)
reference:指定对对应类型定义的引用,重写指定的任何其他数据名称
allowEmptyValue:是否允许传递空值(默认为false)

示例:

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;

import static com.sugon.cloud.lowcode.constants.RegConstant.IP_REG;
import static com.sugon.cloud.lowcode.constants.RegConstant.PORT_REG;

/**
 * @desc 测试连接的请求参数
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
@ApiModel(description = "测试连接的请求参数")
public class DatasourceUrlDto {

  @ApiModelProperty(name = "ip", value = "ip", required = true, example = "127.0.0.1")
  private String ip;

  @ApiModelProperty(name = "port", value = "端口号", required = true, example = "3306")
  private String port;

  @NotBlank(message = "数据库名称不能为空")
  @ApiModelProperty(name = "dbName", value = "数据库名称", required = true, example = "lowCode")
  private String dbName;

  @ApiModelProperty(name = "username", value = "数据库用户名", required = true, example = "root")
  private String username;

  @ApiModelProperty(name = "password", value = "数据库密码", required = true, example = "123456")
  private String password;

  @NotBlank(message = "数据库类型不能为空")
  @ApiModelProperty(
          name = "dialect",
          value = "数据库类型",
          required = true,
          example = "mysql(其他分别为:postgres,sql_server,oracle)")
  private String dialect;
}

你可能感兴趣的:(Java,Web,java,spring,boot,spring)