linux运行vertx,vert.x学习(二),使用Router来定义用户访问路径

本文介绍了如何在Java中使用Vertx和Vertx-Web创建HTTP服务器并定义路由。通过在POM.xml文件中导入vertx-web依赖,然后在HelloRouter.java代码中创建Router对象,配置/hello和/router路径,实现简单的HTTP响应。通过运行代码并在浏览器中访问这些路径,即可看到效果。
摘要由CSDN通过智能技术生成

这里需要用到vertx-web依赖了,依然是在pom.xml里面导入

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

com.javafm

vertx.helloworld

1.0-SNAPSHOT

io.vertx

vertx-web

3.3.3

org.apache.maven.plugins

maven-compiler-plugin

3.6.0

1.8

1.8

这里只需要导入vertx-web就可以了,不需要vertx-core了,因为web依赖了core,会自动导入。而build标签里的maven-compiler-plugin是为了防止每次Import Changes的时候将jdk compiler还原到1.5而设置的。 如果不嫌麻烦,可以手动去设置jdk的编译级别,这个maven-compiler-plugin就可以不用配置了。

编写HelloRouter.java代码

package com.javafm.vertx.helloworld;

import io.vertx.core.Vertx;

import io.vertx.core.http.HttpServer;

import io.vertx.ext.web.Router;

/**

* Created by le

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值