下载架包
注意:Jfinal和Beetl最好2.0以上版本,不然有很多功能和配置不一样
创建config类加载启动项目
package com.demo.common;
import java.io.File;
import java.io.IOException;
import org.bee.tl.core.GroupTemplate;
import org.bee.tl.ext.WebConfig;
import org.bee.tl.ext.jfinal.BeetlRenderFactory;
import com.demo.common.beetl.MyBeetlRenderFactory;
import com.demo.common.controller.HelloController;
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.ext.handler.ContextPathHandler;
import com.jfinal.kit.PathKit;
import com.jfinal.kit.PropKit;
/**
*
* @author
* @时间 2016年9月3日
*/
public class DemoConfig extends JFinalConfig{
@Override
public void configConstant(Constants me) {
/**
* Load property file
* Example: loadPropertyFile("db_username_pass.txt");
* @param file the file in WEB-INF directory
*/
loadPropertyFile("config.properties");
//配置模板
//低版本的jfinal架包没有PropKit这个工具类
String path=PathKit.getWebRootPath();//获取项目的路径D:\apache-tomcat7\apache-tomcat-7.0.65\wtpwebapps\jfinal_demo
me.setMainRenderFactory(new BeetlRenderFactory());
me.setDevMode(getPropertyToBoolean("devMode", false));//设置是否开发模式
me.setEncoding("UTF-8");
}
@Override
public void configRoute(Routes me) {
me.add("/",HelloController.class);
}
@Override
public void configPlugin(Plugins me) {
}
@Override
public void configInterceptor(Interceptors me) {
}
@Override
public void configHandler(Handlers me) {
}
}
3 . 配置web.xml
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<filter>
<filter-name>jfinalfilter-name>
<filter-class>com.jfinal.core.JFinalFilterfilter-class>
<init-param>
<param-name>configClassparam-name>
<param-value>com.demo.common.DemoConfigparam-value>
init-param>
filter>
<filter-mapping>
<filter-name>jfinalfilter-name>
<url-pattern>/*url-pattern>
filter-mapping>
web-app>
4 . 配置beetl.properties文件,此文件要放在src下。如果beetl会先加载默认beetl再加载自己定义的beetl.properties.
#默认配置
DELIMITER_PLACEHOLDER_START=${
DELIMITER_PLACEHOLDER_END=}
DELIMITER_STATEMENT_START=<%
DELIMITER_STATEMENT_END=%>
#HTML_TAG_SUPPORT = false
#HTML_TAG_FLAG = #
NATIVE_CALL = TRUE
COMPILE_CLASS=FALSE
DIRECT_BYTE_OUTPUT = FALSE
TEMPLATE_ROOT=
TEMPLATE_CHARSET = GBK
TEMPLATE_CACHE_CHECK_PERIOD = 2
TEMPLATE_CLASS_FOLDER=
ERROR_HANDLER = org.bee.tl.core.DefaultErrorHandler
MVC_STRICT = FALSE
#内部使用
DEBUG=FALSE
#######默认配置结束
#######性能最佳配置开始
#COMPILE_CLASS=true
#DIRECT_BYTE_OUTPUT = true
########性能最佳配置结束
#######严格MVC配置开始
#MVC_STRICT = TRUE
#NATIVE_CALL = FALSE
########严格MVC配置结束
#######编译成class的其他选项开始,未完全测试,暂时不支持
#COMPILE_CLASS_KEEP_SOURCE=FALSE
#OPTIMIZE_COMPILE_LATTER=FALSE
#OPTIMIZE_COMPILE_WORKER_NUM=2
#######编译成class的其他选项结束
所以配置自己的beetl模板路径时使用:TEMPLATE_ROOT=/WEB-INF/view/
#默认配置
ENGINE=org.beetl.core.engine.FastRuntimeEngine
DELIMITER_PLACEHOLDER_START=${
DELIMITER_PLACEHOLDER_END=}
DELIMITER_STATEMENT_START=<%
DELIMITER_STATEMENT_END=%>
DIRECT_BYTE_OUTPUT = FALSE
HTML_TAG_SUPPORT = true
HTML_TAG_FLAG = #
HTML_TAG_BINDING_ATTRIBUTE = var
NATIVE_CALL = TRUE
TEMPLATE_CHARSET = UTF-8
ERROR_HANDLER = org.beetl.core.ConsoleErrorHandler
NATIVE_SECUARTY_MANAGER= org.beetl.core.DefaultNativeSecurityManager
RESOURCE_LOADER=org.beetl.core.resource.ClasspathResourceLoader
MVC_STRICT = FALSE
### 资源配置,resource后的属性只限于特定ResourceLoader ####
#classpath 跟路径
RESOURCE.root= /
#是否检测文件变化
RESOURCE.autoCheck = TRUE
#自定义脚本方法文件位置
RESOURCE.functionRoot = functions
#自定义脚本方法文件的后缀
RESOURCE.functionSuffix = html
#自定义标签文件位置
RESOURCE.tagRoot = htmltag
#自定义标签文件后缀
RESOURCE.tagSuffix = tag
#如果采用beetl集成的web应用,可以在渲染模板前调用如下类,此类必须实现WebRenderExt接口
WEBAPP_EXT =
#允许html function or Tag 使用特殊的定界符
FUNCTION_TAG_LIMITER=
##### 扩展 ##############
## 内置的方法
FN.date = org.beetl.ext.fn.DateFunction
FN.nvl = org.beetl.ext.fn.NVLFunction
FN.debug = org.beetl.ext.fn.DebugFunction
#兼容以前版本,用has代替
FN.exist = org.beetl.ext.fn.CheckExistFunction
FN.has = org.beetl.ext.fn.CheckExistFunction
FN.printf = org.beetl.ext.fn.Printf
FN.decode = org.beetl.ext.fn.DecodeFunction
FN.assert = org.beetl.ext.fn.AssertFunction
FN.print = org.beetl.ext.fn.Print
FN.println = org.beetl.ext.fn.Println
FN.trunc = org.beetl.ext.fn.TruncFunction
#兼容以前版本 empty,用isEmpty代替
FN.empty = org.beetl.ext.fn.EmptyFunction
FN.qmark = org.beetl.ext.fn.QuestionMark
FN.isEmpty = org.beetl.ext.fn.EmptyExpressionFunction
FN.isNotEmpty = org.beetl.ext.fn.IsNotEmptyExpressionFunction
FN.parseInt = org.beetl.ext.fn.ParseInt
FN.parseLong = org.beetl.ext.fn.ParseLong
FN.parseDouble= org.beetl.ext.fn.ParseDouble
FN.range = org.beetl.ext.fn.Range
FN.flush = org.beetl.ext.fn.Flush
FN.json = org.beetl.ext.fn.Json
FN.pageCtx = org.beetl.ext.fn.PageContextFunction
##内置的功能包
FNP.strutil = org.beetl.ext.fn.StringUtil
FNP.reg = org.beetl.ext.fn.RegxFunctionUtil
FNP.array = org.beetl.ext.fn.ArrayUtil
##内置的格式化函数
FT.dateFormat = org.beetl.ext.format.DateFormat
FT.numberFormat = org.beetl.ext.format.NumberFormat
##内置的默认格式化函数
FTC.java.util.Date = org.beetl.ext.format.DateFormat
FTC.java.sql.Date = org.beetl.ext.format.DateFormat
FTC.java.sql.Time = org.beetl.ext.format.DateFormat
FTC.java.sql.Timestamp = org.beetl.ext.format.DateFormat
FTC.java.lang.Short = org.beetl.ext.format.NumberFormat
FTC.java.lang.Long = org.beetl.ext.format.NumberFormat
FTC.java.lang.Integer = org.beetl.ext.format.NumberFormat
FTC.java.lang.Float = org.beetl.ext.format.NumberFormat
FTC.java.lang.Double = org.beetl.ext.format.NumberFormat
FTC.java.math.BigInteger = org.beetl.ext.format.NumberFormat
FTC.java.math.BigDecimal = org.beetl.ext.format.NumberFormat
FTC.java.util.concurrent.atomic.AtomicLong = org.beetl.ext.format.NumberFormat
FTC.java.util.concurrent.atomic.AtomicInteger = org.beetl.ext.format.NumberFormat
##虚拟属性 无
## 标签类
TAG.include= org.beetl.ext.tag.IncludeTag
TAG.includeFileTemplate= org.beetl.ext.tag.IncludeTag
TAG.layout= org.beetl.ext.tag.LayoutTag
TAG.delete= org.beetl.ext.tag.DeleteTag
TAG.htmltag= org.beetl.ext.tag.HTMLTagSupportWrapper
TAG.htmltagvar= org.beetl.ext.tag.HTMLTagVarBindingWrapper
TAG.cache= org.beetl.ext.tag.cache.CacheTag
所以配置自己的beetl模板路径时使用:RESOURCE.root=/WEB-INF/view/
5 . Controller层
public class HelloController extends Controller{
public void index(){
setAttr("hello", "word");
render("/list.html");
}
}