# 1.0 快速上手

新建maven工程jfinal-5.1.2-hello pom.xml

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <java.version>1.8</java.version>
  <maven.compiler.source>${java.version}</maven.compiler.source>
  <maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
<dependencies>
  <dependency>
    <groupId>com.jfinal</groupId>
    <artifactId>jfinal-undertow</artifactId>
    <version>3.5</version>
  </dependency>

  <dependency>
    <groupId>com.jfinal</groupId>
    <artifactId>jfinal</artifactId>
    <version>5.1.2</version>
  </dependency>
</dependencies>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

HelloController

package demo;

import com.jfinal.core.Controller;
import com.jfinal.core.Path;

@Path("/hello")
public class HelloController extends Controller {
  public void index() {
    renderText("Hello JFinal World.");
  }
}
1
2
3
4
5
6
7
8
9
10
11

DemoConfig

package demo;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.server.undertow.UndertowServer;
import com.jfinal.template.Engine;

public class DemoConfig extends JFinalConfig {

  public void configConstant(Constants me) {
    me.setDevMode(true);
  }

  public void configRoute(Routes me) {
    me.scan("demo.");
  }

  public void configEngine(Engine me) {
  }

  public void configPlugin(Plugins me) {
  }

  public void configInterceptor(Interceptors me) {
  }

  public void configHandler(Handlers me) {
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

DemoApp

package demo;

import com.jfinal.server.undertow.UndertowServer;

public class DemoApp {
  public static void main(String[] args) {
    UndertowServer.start(DemoConfig.class);
  }
}
1
2
3
4
5
6
7
8
9

访问 http://localhost/hello 显示 Hello JFinal World.

代码地址 https://github.com/litongjava/java-ee-jfinal-study/tree/master/jfinal-5.0-study/jfinal-5.1.2-hello

Last Updated: 9/8/2023, 9:00:03 AM