我有一个 Controller xyz.controller.ts
@Get()
fetch(
@Query('id') id: number,
@Query('status') status: string,
@Query('country_id') countryId: number,
@Query('state_id') stateId: number): Promise<any> {
return await this.xyzService(id, status, countryId, stateId);
}
有没有办法将查询参数作为单个对象传递,而不是创建多个函数参数?
最佳答案
如果你在查询中指定键,它只会返回那个键的值,但如果你只是写@Query() query
它会返回整个查询对象然后你可以创建一个接口(interface)给查询对象一个类型,@Query() query: IQuery
关于javascript - 存在多个查询参数时编写代码的更好方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70680854/