最近闲来无事,突发奇想,也顺便练练手,因而就萌生了,可否用typescript的decorator写一个Nodejs SpringMVC,而后就有了这个项目。
该项目支持:javascript
依赖注入Controller ,Service
注入GET/POST/PUT/DELETE/PATCH等rest方法
解析rest api的参数,例如RequestParam
上传文件支持Multer
支持在vscode里面直接debug typescript 的代码java
想学习如何debug typescript代码的同窗能够留意一下,真的很好用。
直接上readMe的部份内容:node
npm i easy-node-ioc --save
Check out the quick start example in test
.git
import { Controller} from 'easy-node-ioc'; @Controller('/test') class TestControl { ... }
import { Service } from 'easy-node-ioc'; @Service('') class TestService { ... }
import { Autowired,Controller } from 'easy-node-ioc'; @Controller('/test') class TestControl { @Autowired testService: TestService; ... }
import { Autowired,Controller,GET,RequestParam } from 'easy-node-ioc'; @Controller('/test') class TestControl { @Autowired testService: TestService; @Get('/index') index(@RequestParam('age') age: number, req: Request, res: Response) { console.log('index method'); this.dbService.queryDb(); res.status(200).send(this.testService.queryDb()); } ... }
import { Bootstrap, ComponentScan } from "../"; @ComponentScan(join(__dirname, "./Controller.ts")) @Bootstrap class App { constructor() {} app = express(); main() { const server = http.createServer(this.app); server.listen(9001, function() { console.log("Example app listening at http://%s:%s"); }); } }
if you use vscode , just follow .vscode/launch.json
, select Launch Program
.
if you see Example app has started.
in the console , then means test case start successfully .
Try to call http://localhost:9001/api/test/index
.github
gitHub地址:https://github.com/chenkang08...typescript
说明:因为这个项目也是突发奇想,可能会存在问题。不过,目前我已经用这个包,重写了我公司内部的一个node后台项目,目前一切运行良好。
同时,欢迎issues,若是你以为还能够,也能够给我一个star。express