NestJS入门:不同请求方式前后端写法

 前文参考:

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);
  }

  • 9
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值