Viktoria Nurieva Asked:2022-09-09 13:06:28 +0000 UTC2022-09-09 13:06:28 +0000 UTC 2022-09-09 13:06:28 +0000 UTC 如何在 Get 请求中使用 @Query() 在 Nest JS 中传递可选参数? 772 在 Swagger 中,我想发送 product_plan 字符串变量,但我也希望能够将此字段留空。我尝试在 product_plan 之后添加一个问号,但它不起作用。请告诉我如何处理这个问题 @Get('getQuery') async getQuery(@Query('product_plan') product_plan?: string): boolean { return true; } nestjs 1 个回答 Voted Best Answer Dmitriy Grape 2022-09-10T04:55:58Z2022-09-10T04:55:58Z 问号只有打字稿需要,但要设置Query参数的文档,您需要使用适当的装饰器:@ApiQuery() @ApiQuery({ name: 'product_plan', required: false }) @Get('getQuery') async getQuery(@Query('product_plan') product_plan?: string): boolean { return true; } https://docs.nestjs.com/openapi/types-and-parameters
问号只有打字稿需要,但要设置
Query参数的文档,您需要使用适当的装饰器:@ApiQuery()https://docs.nestjs.com/openapi/types-and-parameters