小编ale*_*uck的帖子

如何在带有 nestjs 的路由中使用参数?

我想使用 3 条路线:“项目”;'项目/1'; “项目/作者”。但是当我调用“项目/作者”时,触发了“项目/1”并且我收到错误消息。怎么避免呢?

    @Controller('project')
    export class ProjectController {

        @Get()
        async getProjects(@Res() res): Promise<ProjectDto[]> {
            return await this.projectService.getProjects(0, 0).then(projects => res.json(projects));
        }
        @Get(':id')
        async getProject(@Param('id', new ParseIntPipe()) id, @Res() res): Promise<ProjectDto> {
            return await this.projectService.getProjects(id).then(project => res.json(project[0]));
        }

        @Get('/authors')
        async getAuthors(@Res() res): Promise<AuthorDto[]> {
            return await this.projectService.getAuthors().then(authors => res.json(authors));
        }

}
Run Code Online (Sandbox Code Playgroud)

routes nestjs

5
推荐指数
1
解决办法
6064
查看次数

标签 统计

nestjs ×1

routes ×1