资讯专栏INFORMATION COLUMN

Nodejs Spring MVC --支持直接debug ts code

txgcwm / 2182人阅读

摘要:不过,目前我已经用这个包,重写了我公司内部的一个后台项目,目前一切运行良好。

最近闲来无事,突发奇想,也顺便练练手,于是就萌生了,能否用typescript的decorator写一个Nodejs SpringMVC,然后就有了这个项目。
该项目支持:

依赖注入Controller ,Service
注入GET/POST/PUT/DELETE/PATCH等rest方法
解析rest api的参数,例如RequestParam
上传文件支持Multer
支持在vscode里面直接debug typescript 的代码

想学习如何debug typescript代码的同学可以留意一下,真的很好用。
直接上readMe的部分内容:

Installation
npm i easy-node-ioc --save
Quick Start

Check out the quick start example in test.

Usage 1.Create a Controller
import { Controller} from "easy-node-ioc";
@Controller("/test")
class TestControl {
    ...
}
2.Create a Service
import { Service } from "easy-node-ioc";
@Service("")
class TestService {
    ...
}
3.Inject Service
import { Autowired,Controller } from "easy-node-ioc";
@Controller("/test")
class TestControl {
    @Autowired
    testService: TestService;
    ...
}
4.Define Rest API:GET,POST,PUT,DELETE,PATCH
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());
    }
    ...
}
4.Define Start App
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");
    });
  }
}
How to debug

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地址:https://github.com/chenkang08...

说明:由于这个项目也是突发奇想,可能会存在问题。不过,目前我已经用这个包,重写了我公司内部的一个node后台项目,目前一切运行良好。
同时,欢迎issues,如果你觉得还可以,也可以给我一个star。

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/105898.html

相关文章

  • Spring MVC异步处理简介

    摘要:异步处理简介地址相关系列文章异步处理详解分析本文讲到的所有特性皆是基于的,不是基于的。用于异步返回结果,使用自己的,使用负责处理它。配置执行异步操作需要用到,这个可以在用方法来提供相关文档。 Spring MVC异步处理简介 Github地址 相关系列文章: Servlet 3.0 异步处理详解 Servlet 3.1 Async IO分析 本文讲到的所有特性皆是基于Servlet...

    Sike 评论0 收藏0
  • Spring Boot & Spring MVC 异常处理的N种方法

    摘要:定制特定异常返回结果根据官方文档的例子,可以使用和对特定异常返回特定的结果。下面是用浏览器和访问的结果无输出注意上方表格的错误,产生这个的原因前面已经讲过。不过需要注意的是,无法通过设定,由或者容器决定里一律是。 github:https://github.com/chanjarste... 参考文档: Spring Boot 1.5.4.RELEASE Documentation ...

    h9911 评论0 收藏0
  • SpringMVC之初体验--Code-based

    摘要:最后创建了群方便大家交流,可扫描加入,同时也可加我,共同学习共同进步,谢谢 创建项目 创建web项目,使用maven webapp模板进行构建,创建完成后,在pom中引入Spring MVC依赖,如下: org.springframework spring-webmvc 5.0.5.RELEASE javax.servlet ja...

    happyfish 评论0 收藏0
  • Spring Boot 参考指南(开发Web应用程序)

    摘要:开发应用程序非常适合应用程序开发,通过使用嵌入式或,你可以创建一个自包含的服务器。如果你还没有开发过一个应用程序,你可以按照入门部分中的示例进行操作。自动配置为大多数应用程序提供了良好的自动配置。 27. 开发Web应用程序 Spring Boot非常适合web应用程序开发,通过使用嵌入式Tomcat、Jetty、Undertow或Netty,你可以创建一个自包含的HTTP服务器。大多...

    roadtogeek 评论0 收藏0
  • @Validated和@Valid的区别?校验级联属性(内部类)

    摘要:毕竟永远相信本文能给你带来意想不到的收获使用示例关于数据校验这一块在中的使用案例,我相信但凡有点经验的程序员应该没有不会使用的,并且还不乏熟练的选手。 每篇一句 NBA里有两大笑话:一是科比没天赋,二是詹姆斯没技术 相关阅读 【小家Java】深入了解数据校验:Java Bean Validation 2.0(JSR303、JSR349、JSR380)Hibernate-Validati...

    Winer 评论0 收藏0

发表评论

0条评论

txgcwm

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<