一、基本使用
1、基本路由实现
1).增加依赖包
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web</artifactId>
<version>3.5.2</version>
</dependency>
2)、创建一个HttpServer
public class SimpleRouter extends AbstractVerticle {
@Override
public void start() throws Exception {
//创建HttpServer
HttpServer server = vertx.createHttpServer();
//创建路由对象
Router router = Router.router(vertx);
// 监听/index 地址
router.route("/index").handler(request -> {
request.response().end("INDEX SUCCESS");
});
// 把请求交给路由处理
server.requestHandler(router::accept);
server.listen(8888);
}
public static void main(String[] args) {
Vertx.vertx().deployVerticle(new SimpleRouter());
}
}
3)、访问http://localhost:8888/index

2、限制HTTP请求方法
router.post("/post").handler(request -> {
request.response().end("POST SUCCESS");
});

参考:https://blog.csdn.net/king_kgh/article/details/80848571
作者:Work Hard Work Smart
出处:http://www.cnblogs.com/linlf03/
欢迎任何形式的转载,未经作者同意,请保留此段声明!
浙公网安备 33010602011771号