Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为NestJS上带有管道的querystring参数提供默认值_Nestjs - Fatal编程技术网

为NestJS上带有管道的querystring参数提供默认值

为NestJS上带有管道的querystring参数提供默认值,nestjs,Nestjs,我正在尝试实现这个示例。它看起来很容易实现,但我有一些麻烦 @Get('test') async test( @Query('size', new DefaultValuePipe(10), ParseIntPipe) size: number, @Query('page', new DefaultValuePipe(1), ParseIntPipe) page: number, ) { // Do some stuff } 我提出的第一个请求是http://localhost

我正在尝试实现这个示例。它看起来很容易实现,但我有一些麻烦

@Get('test')
async test(
  @Query('size', new DefaultValuePipe(10), ParseIntPipe) size: number,
  @Query('page', new DefaultValuePipe(1), ParseIntPipe) page: number,
) {
   // Do some stuff
}
  • 我提出的第一个请求是
    http://localhost/api/test
    • 我发送的不带参数的请求得到了
      400错误请求的回复
      ,消息是
      验证失败(应为数字字符串)
  • 我提出的第二个请求是
    http://localhost/api/test?size=&page=
    • 使用空参数发送的请求将作为
      0
      传递,而不是默认情况下希望提供的值

在这两个请求中,默认值都应该通过,对吗?如果是这样,我做错了什么?

你能提供一份报告吗?