控制器
get
请求传参
获取@Get()
findAll(@Request() req) {
console.log(req.query);
return {
code: 200,
message: req.query.name,
};
}
@Get()
findAll(@Query() query) {
console.log(query);
return {
code: 200,
message: query.name,
};
}
post
请求
@Post()
create(@Request() req) {
console.log(req);
return {
code: 200,
message: req.body.name,
};
}
@Post()
create(@Body() body) {
console.log(body);
return {
code: 200,
message: body.name,
};
}
向@Body('user')
传参,结构出需要的参数
@Post()
create(@Body('name') name: string, @Body('age') age: string) {
return {
code: 200,
name,
age,
};
}
动态路由参数
@Get(':id')
findId(@Param('id') id: number) {
return {
code: 200,
msg: id,
};
}