自定义指令
示例: 金额格式化
public class Money extends Directive{ @Override public void exec(Env env, Scope scope, Writer writer) { DecimalFormat df = new DecimalFormat("#.00"); Object value = exprList.eval(scope); if (value != null) { value = df.format(value); write(writer, value.toString()); } } } me.addDirective("money", new Money());
#money(price)
2. 类扩展
示例: 非空判读
public class StringKit extends StrKit{ public static boolean isNotBlank(String str){ return !isBlank(str); } } me.addSharedMethod(new StringKit());
#if(isNotBlank(realName)) ... #else ... #end
3. 共享对象扩展
示例:
me.addSharedObject("host_res", "www.jfinal.com/resource"); me.addSharedObject("sk", new StringKit());
<img src="#(host_res)/ico/favicon.ico" /> #if(sk.isNotBlank(realName)) ... #else ... #end
感谢你的分享