[英]Understanding the body decorator in nestjs
Where is the object that references the @body payload stored?引用@body 负载的对象存储在哪里?
If your user controller has a post function.如果您的用户控制器具有发布功能。
@Post() @HttpCode(HttpStatus.CREATED) create(@Body() user: IUserBase): Promise { return this.usersService.create(user); @Post() @HttpCode(HttpStatus.CREATED) create(@Body() user: IUserBase): Promise { return this.usersService.create(user); } }
Where is the user variable stored?用户变量存储在哪里? Is it stored in the request object of the nest.js server?是存储在nest.js服务器的请求对象中吗?
It is injected into the function as an argument.它作为参数注入到函数中。
The @body
decorator basically says: @body
装饰器基本上说:
Please cast the json that arrives in the request body into IUserBase
type and place it as a parameter to this controller's handler.请将请求正文中到达的 json 转换为IUserBase
类型,并将其作为参数放置到此控制器的处理程序中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.