02232017
This commit is contained in:
parent
5df00eeacd
commit
28132992c8
|
@ -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: []
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,8 +34,9 @@ import { ResourceModule } from '@server/models/resource/resource.module';
|
|||
VisitModule,
|
||||
WebSocketModule,
|
||||
ResourceModule,
|
||||
GoodsModule
|
||||
],
|
||||
controllers: [],
|
||||
providers: [TrpcService, TrpcRouter, Logger],
|
||||
})
|
||||
export class TrpcModule {}
|
||||
export class TrpcModule { }
|
||||
|
|
|
@ -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" >
|
||||
|
|
Loading…
Reference in New Issue