student-manage/apps/server/src/models/goods/goods.controller.ts

42 lines
914 B
TypeScript
Raw Normal View History

2025-02-23 20:17:53 +08:00
import { Controller, Get, Query, Param } from '@nestjs/common';
2025-02-23 19:37:11 +08:00
@Controller('goods')
export class GoodsController {
2025-02-23 20:17:53 +08:00
constructor() {
console.log('goods controller')
}
// 示例1基本查询参数
2025-02-23 19:37:11 +08:00
@Get('hello')
2025-02-23 20:17:53 +08:00
getHello(@Query('name') name?: string) {
return {
message: 'Hello World!',
name: name || 'Guest'
};
}
// 示例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: []
};
2025-02-23 19:37:11 +08:00
}
}