This commit is contained in:
longdayi 2025-02-23 20:17:53 +08:00
parent 5df00eeacd
commit 28132992c8
3 changed files with 46 additions and 6 deletions

View File

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

View File

@ -16,6 +16,7 @@ import { RoleMapModule } from '@server/models/rbac/rbac.module';
import { TransformModule } from '@server/models/transform/transform.module';
import { ResourceModule } from '@server/models/resource/resource.module';
import { GoodsModule } from '@server/models/goods/goods.module';
@Module({
imports: [
@ -33,6 +34,7 @@ import { ResourceModule } from '@server/models/resource/resource.module';
VisitModule,
WebSocketModule,
ResourceModule,
GoodsModule
],
controllers: [],
providers: [TrpcService, TrpcRouter, Logger],

View File

@ -1,4 +1,5 @@
import { api } from "@nice/client"
import { apiClient } from "@web/src/utils"
import { Button, Tag } from "antd"
import { useEffect, useMemo, useState } from "react"
@ -10,9 +11,14 @@ function HomePage() {
const counterText = useMemo(() => {
return `当前计数为:${counter}`
}, [counter])
const getData = async () => {
const res = await apiClient.get("/goods/hello")
console.log(res)
}
useEffect(() => {
console.log(data)
}, [data])
getData()
}, [])
return <div className="p-2 space-y-2">
<Tag>{counterText}</Tag>
<div className="space-x-2" >