一、先下載官方demohtml
http://www.jfinal.com/download/now?file=jfinal-2.2_demo.zipjava
二、複製全部jar包到本身項目的lib下web
三、將一下配置信息複製到web.xml中apache
<filter> <filter-name>jfinal</filter-name> <filter-class>com.jfinal.core.JFinalFilter</filter-class> <init-param> <param-name>configClass</param-name> <param-value>cn.liem.jfinal.demo.config.DemoConfig</param-value> </init-param> </filter> <filter-mapping> <filter-name>jfinal</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
四、建立DemoConfig.javaapp
package cn.liem.jfinal.demo.config; import cn.liem.jfinal.demo.index.IndexController; 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.core.JFinal; import com.jfinal.kit.PropKit; /** * API引導式配置 */ public class DemoConfig extends JFinalConfig { /** * 建議使用 JFinal 手冊推薦的方式啓動項目 * 運行此 main 方法能夠啓動項目,此main方法能夠放置在任意的Class類定義中,不必定要放於此 */ public static void main(String[] args) { // 特別注意idea中寫web,eclipse中爲WebRoot JFinal.start("web", 8089, "/", 5); } /** * 配置常量 */ public void configConstant(Constants me) { me.setDevMode(true); } /** * 配置路由 */ public void configRoute(Routes me) { // 第三個參數爲該Controller的視圖存放路徑 me.add("/", IndexController.class, "/index"); // 第三個參數省略時默認與第一個參數值相同,在此即爲 "/index" // me.add("/index", IndexController.class); } /** * 配置插件 */ @Override public void configPlugin(Plugins me) { } /** * 配置全局攔截器 */ public void configInterceptor(Interceptors me) { } /** * 配置處理器 */ public void configHandler(Handlers me) { } }
五、建立IndexController.javaeclipse
package cn.liem.jfinal.demo.index; import com.jfinal.core.Controller; /** * IndexController */ public class IndexController extends Controller { public void index() { // 傳遞參數到前臺 setAttr("hello","hello JFinal...."); render("index.html"); } }
五、在src根目錄下建立log4j.propertieside
log4j.rootLogger=WARN, stdout, file log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%n%-d{yyyy-MM-dd HH:mm:ss}%n[%p]-[Thread: %t]-[%C.%M()]: %m%n # Output to the File log4j.appender.file=org.apache.log4j.FileAppender log4j.appender.file.File=./jfinal_demo.log log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%n%-d{yyyy-MM-dd HH:mm:ss}%n[%p]-[Thread: %t]-[%C.%M()]: %m%n
六、建立htmlui
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <h1>${hello}</h1> </body> </html>
七、上一個總體項目結構截圖url
八、執行DemoConfig中的main方法啓動idea
九、輸入http://localhost:8089/訪問