var JDBCClient = require("vertx-jdbc-js/jdbc_client"); var Router = require("vertx-web-js/router"); var BodyHandler = require("vertx-web-js/body_handler"); var client; var setUpInitialData = function(done) { client.getConnection(function (res, res_err) { if (res_err != null) { throw res_err; } var conn = res; conn.execute("CREATE TABLE IF NOT EXISTS products(id INT IDENTITY, name VARCHAR(255), price FLOAT, weight INT)", function (ddl, ddl_err) { if (ddl_err != null) { throw ddl_err; } conn.execute("INSERT INTO products (name, price, weight) VALUES ('Egg Whisk', 3.99, 150), ('Tea Cosy', 5.99, 100), ('Spatula', 1.00, 80)", function (fixtures, fixtures_err) { if (fixtures_err != null) { throw fixtures_err; } done.handle(null); }); }); }); }; var that = this; // Create a JDBC client with a test database client = JDBCClient.createShared(vertx, { "url" : "jdbc:hsqldb:mem:test?shutdown=true", "driver_class" : "org.hsqldb.jdbcDriver" }); setUpInitialData(function (ready) { var router = Router.router(vertx); router.route().handler(BodyHandler.create().handle); // in order to minimize the nesting of call backs we can put the JDBC connection on the context for all routes // that match /products // this should really be encapsulated in a reusable JDBC handler that uses can just add to their app router.route("/products*").handler(function (routingContext) { client.getConnection(function (res, res_err) { if (res_err != null) { routingContext.fail(res_err); } else { var conn = res; // save the connection on the context routingContext.put("conn", conn); // we need to return the connection back to the jdbc pool. In order to do that we need to close it, to keep // the remaining code readable one can add a headers end handler to close the connection. The reason to // choose the headers end is that if the close of the connection or say for example end of transaction // results in an error, it is still possible to return back to the client an error code and message. routingContext.addHeadersEndHandler(function (done) { conn.close(function (close, close_err) { if (close_err != null) { done.fail(close_err); } else { done.complete(); } }); }); routingContext.next(); } }); }).failureHandler(function (routingContext) { var conn = routingContext.get("conn"); if (conn !== null) { conn.close(function (v, v_err) { }); } }); router.get("/products/:productID").handler(that.handleGetProduct); router.post("/products").handler(that.handleAddProduct); router.get("/products").handler(that.handleListProducts); vertx.createHttpServer().requestHandler(router.accept).listen(8080); });
相关推荐
vertx.web开发,h2数据库基本的操作,httpclient发出get、post请求。
javascript Vertx开发教程
Vertx JDBC 执行器 JDBC Executor 为通过 Vertx 3.0 事件总线访问任何符合 JDBC 的数据源提供了一种快速有效的方法。 与 Executor 的所有交互都应该是原子的,并且尽可能“简短而甜蜜”,以尽量减少对共享(JDBC ...
vertx-service-demo
包含翻译后的API文档:vertx-web-3.9.0-javadoc-API文档-中文(简体)版.zip; Maven坐标:io.vertx:vertx-web:3.9.0; 标签:vertx、web、中文文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开...
包含翻译后的API文档:vertx-web-3.9.0-javadoc-API文档-中文(简体)-英语-对照版.zip; Maven坐标:io.vertx:vertx-web:3.9.0; 标签:vertx、web、中英对照文档、jar包、java; 使用方法:解压翻译后的API文档,用...
包含翻译后的API文档:vertx-core-3.9.0-javadoc-API文档-中文(简体)-英语-对照版.zip; Maven坐标:io.vertx:vertx-core:3.9.0; 标签:vertx、core、中英对照文档、jar包、java; 使用方法:解压翻译后的API文档,...
包含翻译后的API文档:vertx-core-3.9.0-javadoc-API文档-中文(简体)版.zip; Maven坐标:io.vertx:vertx-core:3.9.0; 标签:vertx、core、中文文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开...
包含翻译后的API文档:vertx-bridge-common-3.9.0-javadoc-API文档-中文(简体)版.zip; Maven坐标:io.vertx:vertx-bridge-common:3.9.0; 标签:vertx、bridge、common、中文文档、jar包、java; 使用方法:解压...
包含翻译后的API文档:vertx-auth-common-3.9.0-javadoc-API文档-中文(简体)版.zip; Maven坐标:io.vertx:vertx-auth-common:3.9.0; 标签:vertx、auth、common、中文文档、jar包、java; 使用方法:解压翻译后的...
NULL 博文链接:https://kingxss.iteye.com/blog/1479451
使用IDEA和Gradle构建Vertx项目,详细操作步骤,也可以去查阅我的博客文章
自己写的一个java+vertx+mybatis的网关、服务分发,用于app后台接口开发的基本框架,仅供参考,请不要用于商业用途。
包含翻译后的API文档:vertx-bridge-common-3.9.0-javadoc-API文档-中文(简体)-英语-对照版.zip; Maven坐标:io.vertx:vertx-bridge-common:3.9.0; 标签:vertx、bridge、common、中英对照文档、jar包、java; ...
TPA API BASED ON VERTX
vertx3基本详情入门讲解,ppt格式的,里面含有vertx3的基本讲解和重要的组建信息
vertx-cluster-demo 基于Hazelcast的群集管理器的Vert.x示例
liquibase-slf4j.zip,Liquibase SLF4J LoggerLiquibase SLF4J记录器。
vertx_cheatsheet
Vert.x网站 该存储库包含Vert.x网站( ... 测试导出的网站: cd outnpx serve码头工人如果您不想安装Node.js,请改用Docker: # Initialize local copyrm -rf node_modulesdocker run -it -v $(pwd):/vertx node:14-sli