1.管道
import { Controller,Get,Param,ParseIntPipe,ParseUUIDPipe} from '@nestjs/common';
import { PipeService } from './pipe.service';
import * as uuid from 'uuid'
console.log(uuid.v4())
@Controller('pipe')
export class PipeController {
constructor(private readonly pipeService: PipeService) {}
@Get(':id')
findOne(@Param('id',ParseUUIDPipe) id: string) {
console.log(typeof id,'12121====>')
return 'pipe'
}
}
2.验证dto
import {ValidationPipe} from "@nestjs/common";
import {IsNotEmpty,IsString,Length,IsNumber} from 'class-validator'
export class CreateLoginDto {
@IsNotEmpty()
@IsString()
@Length(5,10,{
message:"不能超过十个字符"
})
name:string;
@IsNumber()
age:number
}
@Post()
create(@Body() createLoginDto: CreateLoginDto) {
return this.loginService.create(createLoginDto);
}