NestJS Controller

NestJS|2021. 11. 17. 08:05

Spring과 거의 비슷

 

import { Controller, Get, Render, Param, Query } from '@nestjs/common';
import { AppService } from './app.service';

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get()
  getHello(): string {
    return this.appService.getHello();
  }

  @Get("html")
  @Render('index')
  getHbs(){
    return { message: 'messageBinding' };
  }

  @Get(':id')
  findOne(@Param('id') id: string, @Query('getParam') getParam): string {
    
    console.log('getParam : ${getParam}')
    console.log("getParam : ${getParam}")
    console.log(`getParam : ${getParam}`)
    return `This action returns a #${id} cat`;
  }
}

 

Spring Next.js  
@{HttpMethod}Mapping @{HttpMethod}() @GetMapping -> @Get()
@PathVariable @Param()  
@RequestParam @Query()  
@RequestBody @Body() DTO로 바인딩도 가능
@ResponseEntity @Res() res 아래와 같은 방식으로 response 응답 정의 가능
res.status(HttpStatus.OK).json()

 

 

 

'NestJS' 카테고리의 다른 글

NestJS 시작  (0) 2021.10.21

댓글()