class-validator只要您不添加装饰器,这就是标准功能@IsOptional()。我将管道直接添加到控制器,但想法是相同的。请参阅下面的我的课程和标注: // test-class.ts import { IsString, IsOptional } from 'class-validator'; export class TestClass { @IsString() address1: string; @IsString() @IsOptional(...
@IsOptional() Checks if given value is empty (=== null, === undefined) and if so, ignores all the validators on the property. 检查给定值是否为空(=== null, === undefined) ,如果是,则忽略属性上的所有验证程序 @Equals(comparison: any) Checks if value equals ("===") comparison. 检查...
只要不添加@IsOptional()装饰器,这就是class-validator的标准功能。我将管道直接添加到控制器中,但想法...
2、对象嵌套对象型--{key:object} 例如:{merchant_synchronize_price_rule_id?: '1',rate: 2,difference_amount: 12.00,is_inclusive_lowest_threshold_amount: true, lowest_threshold_amount: 14.23, status: 'qy' } 代码如下: class SynchronizePriceRule { @V.IsOptional() @V.IsNumberString() merchant_...
IsDate 必须是Date类型了 IsNumber Number类型就可以 IsInt 整数通过 IsArray 必须是数组 IsEnum(entity: object) IsObject 判断是否是一个对象 IsNotEmptyObject() 不是空对象 常用校验器 IsDefined 不能等于null或者undefined 空字符串可以的 IsOptional 常用 ...
@IsOptional()Checks if given value is empty (=== null, === undefined) and if so, ignores all the validators on the property.检查给定值是否为空(=== null, === undefined) ,如果是,则忽略属 性上的所有验证程序 @Equals(comparison:any)Checks if value equals ("===") comparison.检查值...
IsDefined registerDecorator View more ... Other Related APIs typeorm#SelectQueryBuilder class-validator#Length class-validator#IsString class-validator#IsNumber class-validator#IsEmail class-validator#IsDefined class-validator#IsBoolean class-validator#IsOptional class-validator#IsInt class...
IsArray 必须是数组 IsEnum(entity: object) IsObject 判断是否是一个对象 IsNotEmptyObject() 不是空对象 常用校验器 IsDefined 不能等于null或者undefined 空字符串可以的 IsOptional 常用 可选的。如果输入的等于null或者undefined,忽略其它的校验装饰器 ...
import{IsNumber,IsString,IsOptional,IsNotEmpty,IsArray,}from'class-validator';exportclassDataDto{@IsArray()@ArrayNotEmpty()@ValidateNested({each:true})@Type(()=>UserDto)readonly list:UserDto[]}exportclassUserDto{@IsString()@IsNotEmpty()name:string@IsNumber()age?:number} ...
import { IsOptional, Equals, validator } from 'class-validator-multi-lang'; class MyClass { @IsOptional() @Equals('test') title: string = 'bad_value'; } const RU_I18N_MESSAGES = { '$property must be equal to $constraint1': '$property должнобытьравно $constraint1...