最近閒來無事,突發奇想,也順便練練手,因而就萌生了,可否用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