2031
This commit is contained in:
parent
10dda20662
commit
6cf6248b59
|
@ -0,0 +1,39 @@
|
|||
import { Controller, Get, Param, Query } from '@nestjs/common';
|
||||
|
||||
@Controller('goods')
|
||||
export class GoodsController {
|
||||
constructor() {
|
||||
console.log('goods Controller');
|
||||
}
|
||||
@Get('hello')
|
||||
getHello(): string {
|
||||
return 'Hello World!';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 示例2:路径参数
|
||||
@Get('detail/:id')
|
||||
getDetail(@Param('id') id: string) {
|
||||
return {
|
||||
id: id,
|
||||
detail: `Detail for product ${id}`
|
||||
};
|
||||
}
|
||||
|
||||
// 示例3:多个查询参数
|
||||
@Get('search')
|
||||
searchProducts(
|
||||
@Query('keyword') keyword: string,
|
||||
@Query('page') page: number = 1,
|
||||
@Query('limit') limit: number = 10
|
||||
) {
|
||||
return {
|
||||
keyword,
|
||||
page,
|
||||
limit,
|
||||
results: []
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { GoodsService } from './goods.servers';
|
||||
import { GoodsController } from './goods.controller';
|
||||
|
||||
|
||||
@Module({
|
||||
providers: [GoodsService],
|
||||
controllers: [GoodsController]
|
||||
})
|
||||
export class GoodsModule {}
|
|
@ -0,0 +1,7 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class GoodsService {
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue