跳至主要內容

快速上手

大约 1 分钟

快速上手

依赖环境

FastChar 要求Java1.8以上版本。

运行容器

tomcatopen in new windowjettyopen in new windowundertowopen in new window

Maven搭建项目

Maven搭建项目,按照以下三步即可极速搭建FastChar项目,推荐使用Maven搭建项目!省心省事省力!

注意

以下的代码演示所使用的FastChar版本必须在2.0.0以上。

<dependency>
    <groupId>com.fastchar</groupId>
    <artifactId>fastchar</artifactId>
    <version>2.0.2</version>
</dependency>
  • 步骤 2: 在任意的package中创建TestAction类并继承FastAction类,如下代码:
public class TestAction extends FastAction {
    /**
     * 获得路由地址
     * Get routing address
     * @return
     */
    @Override
    protected String getRoute() {
        return "/test";
    }
 
    public void index() {
        responseText("搭建成功!");
    }
}
  • 步骤 3: 使用Tomcat服务运行项目,访问项目地址即可,例如上述案例中的项目名为FastCharTest,那么访问的地址:http://localhost:8080/FastCharTest/test/

手动搭建项目

注意

以下的代码演示所使用的FastChar版本必须在2.0.0以上。

  • 步骤 1: 下载FastChar的Maven Centralopen in new window ,并引用到Web项目中。

  • 步骤 2: 在任意的package中创建TestAction类并继承FastAction类,如下代码:

public class TestAction extends FastAction {
    /**
     * 获得路由地址
     * Get routing address
     * @return
     */
    @Override
    protected String getRoute() {
        return "/test";
    }
 
    public void index() {
        responseText("搭建成功!");
    }
}
  • 步骤 3: 使用Tomcat服务运行项目,访问项目地址即可,例如上述案例中的项目名为FastCharTest,那么访问的地址:http://localhost:8080/FastCharTest/test/
上次编辑于:
贡献者: Janesen