Rain for Deno 基于TypeScript装饰器的IOC服务器框架

1 篇文章 0 订阅
1 篇文章 0 订阅

github: https://github.com/awayel/Rain-for-Deno

说明

个人Deno的试水框架,模仿Spring Boot的注解和注解用法,使用TypeScript装饰器开发服务器框架。
装饰器类似于java的springMVC框架注释用法
带有@Controller装饰器的导出类,可被扫描到并装配至容器内。
部分装饰器用法受限于装饰器本身,而不同于springMVC,如@AutoWired需要传入类名,@Param需要加上参数名。 提供装饰器:Controller, GetMapping, PostMapping, Value, AutoWired, Param,Configuration,Repository。

安装说明:

  • 安装依赖官网: Deno: https://deno.land/
  • git clone https://github.com/awayel/Rain-for-Deno.git
  • deno run --allow-net --allow-read --allow-write app.ts
import { Controller, GetMapping, PostMapping, Value, AutoWired, Param,RequestBody} from '../../rain/index.ts';
import UserService from '../service/UserService.ts'
import User from '../entity/User.ts'

@Controller("/userController")
class UserController {

    @AutoWired(UserService)
    private userService!: UserService;

    @PostMapping("/login", "multipart/form-data")
    public async login(@Param('id', 'number') id: number) {
        const user = await this.userService.getInfo(id);
        return {
            code: 200,
            message: "登录成功",
            data: user
        }
    }

    @PostMapping("/addUser","application/json")
    public async addUser(@RequestBody user: User) {
        const result =  await this.userService.addUser(user);
        return {
            code: 200,
            message: "登录成功",
            data: result
        }
    }
}

export default UserController;

项目目录结构:

在这里插入图片描述

提供API文档功能(临时,待完善)

/rain-doc/index.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值