0.0.1 • Published 2 years ago
tiantong v0.0.1
Quick Start
基于Bun的类springboot框架
已实现功能
- Module
- Controller
- Service
- Injectable
- Provider
已实现功能路由修饰器
- @Post
- @Get
已实现功能参数修饰器
- @Query
- @Param
- @Body
In Node.js
npm install -g bun
npm install tiantong --saveimport { Factory } from 'tiantong'
import { AppModule } from './app.module'
Factory.create({ module: AppModule })
Factory.listen(3000)Module
import { UserController } from '@/modules/user/user.controller.ts'
import { UserService } from '@/modules/user/user.service.ts'
import { Module }  from 'tiantong'
@Module({
  controllers: [UserController],
  providers: [UserService],
})
export class UserModule {}Controller
import { UserService } from '@/modules/user/user.service.ts'
import { Body, Controller, Get, Param, Post } from 'tiantong'
@Controller('user')
export class UserController {
  test: string
  constructor(private userService: UserService) {
    this.test = 'test1111'
  }
  @Get('')
  getUser(@Param('id') id: number) {
    return {
      id,
    }
  }
  
  @Post('add')
  addUser(@Body() body: any, @Body('id') id: number) {
    return {
      id,
      body,
      this: this,
      str: 'add user',
      userService: this.userService.getUser(),
    }
  }
  
  @get('delete/:id')
  addUser(@Param('id') id: string) {
    return {
      id,
    }
  }
}Server
import { Injectable } from 'tiantong'
@Injectable()
export class UserService {
  getUser() {
    return 'test'
  }
}