- 目前可用装饰器:
@Get
, @Post
, @Put
, @Delete
, @Body
, @Query
, @injectRouter
-
npm install
-
npm run example
// user/controller
@Controller('/user')
export default class UserContorller {
@Get()
public async find() {
return 'userGet';
}
@Get('/one')
public async findOne(@Query('id') id: number) {
return {
code: 0,
success: 'success',
data: id,
};
}
}
// hello/controller.ts
@Controller('/hello')
export default class HelloContorller {
@Get()
public async find() {
return '123get';
}
@Post()
public async create(
@Body('hello') hello: string,
@Body('world') world: string
) {
return {
code: 0,
message: 'success',
data: hello + world,
};
}
}
@injectRouter([HelloContorller, UserContorller])
class Main extends Application {
public static async run() {
this.use(logger());
this.listen(3000);
}
}
Main.run();