midway icon indicating copy to clipboard operation
midway copied to clipboard

[Question]@Body如果遇到客户端有某个值没传,后面的参数全部会变成所有数据对象

Open xmsz opened this issue 4 years ago • 3 comments

背景

  @Post('/daily/sync')
  async dailySync(
    @Body() userId: number,
    @Body() date: string,
    @Body() actId: number,
    @Body() test: string
  ) {
      console.log(userId, date, actId, test);
  }

如果我传递

{
 userId: 1,
 actId: 1,
}

则结果会变成

1, undefied, { userId: 9, actId: 1 }, { userId: 9, actId: 1 }

xmsz avatar Jul 19 '21 04:07 xmsz

image image

应该修复了吧

chenzhaozheng avatar Aug 17 '21 01:08 chenzhaozheng

还是 @Body(ALL) 比较好,还方便用 interface 做参数类型校验

waitingsong avatar Aug 18 '21 02:08 waitingsong

还是 @Body(ALL) 比较好,还方便用 interface 做参数类型校验

是的

chenzhaozheng avatar Aug 25 '21 02:08 chenzhaozheng

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Aug 21 '23 08:08 github-actions[bot]