在IDEA中创建web项目并添加maven
在pom.xml中配置
<dependencies>
<dependency>
<groupId>com.jfinal</groupId>
<artifactId>jetty-server</artifactId>
<version>8.1.8</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.jfinal</groupId>
<artifactId>jfinal</artifactId>
<version>3.3</version>
</dependency>
</dependencies>
在创建config配置类
package gui.config;
import com.jfinal.config.*;
import com.jfinal.template.Engine;
import gui.controller.HelloController;
public class JFinalConfig extends com.jfinal.config.JFinalConfig {
public void configConstant(Constants constants) {
constants.setDevMode(true);
}
public void configRoute(Routes routes) {
routes.add("/hello", HelloController.class);
}
public void configEngine(Engine engine) {
}
public void configPlugin(Plugins plugins) {
}
public void configInterceptor(Interceptors interceptors) {
}
public void configHandler(Handlers handlers) {
}
}
创建controller
package gui.controller;
import com.jfinal.core.Controller;
public class HelloController extends Controller {
public void index (){
renderText("Hello world");
}
}
在web.xml中配置过滤器
<filter>
<filter-name>jfinal</filter-name>
<filter-class>com.jfinal.core.JFinalFilter</filter-class>
<init-param>
<param-name>configClass</param-name>
<param-value>gui.config.JFinalConfig</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>jfinal</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
运行使用tomcat运行项目