前文参考:
NestJS入门1
NestJS入门2:创建模块
//GET http://localhost:3000/user
@Get()
async findAll() {
return this.userService.findAll();
}
// POST http://localhost:3000/user Body加上X-www-form-urlencoded数据
@Post()
create(@Body() createUserDto: CreateUserDto) {
return this.userService.create(createUserDto);
}
//GET http://localhost:3000/user/4
@Get(':id')
findOne(@Param('id') id: string) {
console.log('Get ' + id);
return this.userService.findOne(+id);
}
//GET http://localhost:3000/user/getId?id=5
@Get('/getId')
findOne(@Query('id') id: string) {
return this.userService.findOne(+id);
}
//PATCH http://localhost:3000/user/1 Body加上数据
@Patch(':id')
update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) {
console.log('Patch ' + id);
console.log(UpdateUserDto);
return this.userService.update(+id, updateUserDto);
}
//DELETE http://localhost:3000/user/1
@Delete(':id')
remove(@Param('id') id: string) {
console.log('Delete ' + id);
return this.userService.remove(+id);
}