Home

Nestjs入门(四)

1970-01-01 00:00:00

发表时间: 2019-02-26

摘要

nestjs入门系列四

前言

现在进入真正的代码阶段,由于代码量比较多,在这一节里只放一些关键的代码,或者是没有实现方法的代码。

开始

hero.controller.ts 看起来大概是下面的样子。

import { Controller, Get, Delete, Put, Post, Param, Body } from '@nestjs/common';
import { HeroService } from './hero.service';

@Controller('hero')
export class HeroController {
  constructor(private readonly heroService: HeroService) { }

  @Get()
  heroes() {
    return this.heroService.findAll();
  }

  @Get(':id')
  findOne(@Param('id') heroId) {
    return this.heroService.findOne(heroId);
  }

  @Put(':id')
  updateHero(@Param('id') heroId, @Body() hero) {
    return this.heroService.updateHero(heroId, hero);
  }

  @Post()
  wizard(@Body() hero) {
    return this.heroService.wizard(hero);
  }

  @Delete(':id')
  deleteOne(@Param('id') heroId) {
    return this.heroService.deleteOne(heroId);
  }
}

尾巴

可运行的例子将会拖布到我的Github repo,可以按照 readme.md说明进行项目运行。用户状态当前暂未实现。

在下面尝试评论这篇Blog

关于我 联系我 Awesome