项目结构
具体代码
//DemoConfig.java
package com.demo.config;
import com.demo.controller.HelloController;
import com.jfinal.config.*;
import com.jfinal.template.Engine;
public class DemoConfig extends JFinalConfig {
@Override
public void configConstant(Constants me) {
me.setDevMode(true);
}
@Override
public void configRoute(Routes me) {
me.add("/hello", HelloController.class);
}
@Override
public void configEngine(Engine me) {
}
@Override
public void configPlugin(Plugins me) {
}
@Override
public void configInterceptor(Interceptors me) {
}
@Override
public void configHandler(Handlers me) {
}
}
//HelloController.java
package com.demo.controller;
import com.jfinal.core.Controller;
public class HelloController extends Controller {
public void index(){
renderText("hello world!");
}
}
//web.xml
<!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>com.demo.config.DemoConfig</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>jfinal</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
//pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>jfinal-web-demo</groupId>
<artifactId>jfinal-demo</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>jfinal-web-demo-provider</artifactId>
<packaging>war</packaging>
<name>jfinal-web-demo-provider Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jfinal</groupId>
<artifactId>jfinal</artifactId>
</dependency>
</dependencies>
<build>
<finalName>jfinal-web-demo-provider</finalName>
<plugins>
<plugin>
<!--maven对应的tomcat插件,启动tomcat的时候使用-->
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>8081</port>
<path>/</path>
<uriEncoding>utf-8</uriEncoding>
</configuration>
</plugin>
</plugins>
</build>
</project>