This commit is contained in:
weiyida 2025-02-23 20:31:53 +08:00
parent 10dda20662
commit 6cf6248b59
3 changed files with 56 additions and 0 deletions

View File

@ -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: []
};
}
}

View File

@ -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 {}

View File

@ -0,0 +1,7 @@
import { Injectable } from '@nestjs/common';
@Injectable()
export class GoodsService {
}