demo下载
https://download.csdn.net/download/qq_43560721/12517578
1.创建maven web项目
新建
选择
填写maven项目基本属性
配置本地maven路径
Finish
2.新建文件夹java,资源文件夹resources
java->Mark Directory as->Sources Root
resources->Mark Directory as->Resources Root
3.添加依赖
<dependency>
<groupId>com.jfinal</groupId>
<artifactId>jfinal</artifactId>
<version>3.3</version>
</dependency>
<dependency>
<groupId>com.jfinal</groupId>
<artifactId>jetty-server</artifactId>
<version>8.1.8</version>
<!-- <scope>provided</scope>-->
</dependency>
4.编码
import com.jfinal.core.Controller;
/**
* @Author xxs
* @Date 2020/6/11 19:55
*/
public class HelloController extends Controller {
public void index(){
renderText("Hello JFinal World.");
}
}
配置HelloController到jfinal中
import com.jfinal.config.*;
import com.jfinal.template.Engine;
/**
* @Author xxs
* @Date 2020/6/11 19:56
*/
public class DemoConfig extends JFinalConfig {
@Override
public void configConstant(Constants constants) {
constants.setDevMode(true);
}
@Override
public void configRoute(Routes routes) {
routes.add("/hello",HelloController.class);
}
@Override
public void configEngine(Engine engine) {
}
@Override
public void configPlugin(Plugins plugins) {
}
@Override
public void configInterceptor(Interceptors interceptors) {
}
@Override
public void configHandler(Handlers handlers) {
}
}
将DemoConfig配置到拦截器中
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<filter>
<filter-name>jfinal</filter-name>
<filter-class>com.jfinal.core.JFinalFilter</filter-class>
<init-param>
<param-name>configClass</param-name>
<param-value>DemoConfig</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>jfinal</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
启动类
import com.jfinal.core.JFinal;
/**
* @Author xxs
* @Date 2020/6/11 19:59
*/
public class Application {
public static void main(String[] args) {
JFinal.start("src/main/webapp", 8080, "/", 5);
}
}
5.测试:
运行启动类
访问