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

41 lines
913 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Controller, Get, Query, Param } from '@nestjs/common';
@Controller('goods')
export class GoodsController {
constructor() {
console.log('goods controller')
}
// 示例1基本查询参数
@Get('hello')
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: []
};
}
}