Jfinal entry cases and problems encountered

Jfinal entry cases and problems encountered

1. Use idea to create maven project

2. Add jfinal-undertow and jfinal dependencies 

  Open the pom.xml file and add the following dependencies

<dependency>
    <groupId>com.jfinal</groupId>
    <artifactId>jfinal-undertow</artifactId>
    <version>2.1</version>
</dependency>
 
<dependency>
    <groupId>com.jfinal</groupId>
    <artifactId>jfinal</artifactId>
    <version>4.9.01</version>
</dependency>
If you need WebSocket support, add another dependency, don’t need to worry about not developing WebSocket (just started, not involved yet)
<dependency>
    <groupId>io.undertow</groupId>
    <artifactId>undertow-websockets-jsr</artifactId>
    <version>2.0.30.Final</version>
</dependency>

 

3. Add java files

Create a demo package under the project src/main/java directory, and create a DemoConfig file under the demo package

package demo;
 
import com.jfinal.config.*;
import com.jfinal.template.Engine;
import com.jfinal.server.undertow.UndertowServer;
 
public class DemoConfig extends JFinalConfig {
 
    /**
     * 注意:用于启动的 main 方法可以在任意 java 类中创建,在此仅为方便演示
     *      才将 main 方法放在了 DemoConfig 中
     *
     *      开发项目时,建议新建一个 App.java 或者 Start.java 这样的专用
     *      启动入口类放置用于启动的 main 方法
     */
    public static void main(String[] args) {
        UndertowServer.start(DemoConfig.class, 80, true);
    }
 
    public void configConstant(Constants me) {
       me.setDevMode(true);
    }
    
    public void configRoute(Routes me) {
       me.add("/hello", HelloController.class);
    }
    
    public void configEngine(Engine me) {}
    public void configPlugin(Plugins me) {}
    public void configInterceptor(Interceptors me) {}
    public void configHandler(Handlers me) {}
}

Create a HelloController class file in the demo package, the content is as follows

package demo;
import com.jfinal.core.Controller;
 
public class HelloController extends Controller {
    public void index() {
       renderText("Hello JFinal World.");
    }
}

4. Start the project 

 

5. Open the browser to see the effect

 

 

 

  

 

 

 

Guess you like

Origin blog.csdn.net/NewDay_/article/details/108415329