JFinal �ֲ�

 

 

 

 

 

 

 

 

 

 

�汾:  1.8 ����:  ղ��

����:  2014-05-23 http://www.jfinal.com

 

 

 

 

1.1 ������Ŀ... 7

1.2 ���� JFinal ���ļ�... 10

1.3 �޸� web.xml 10

1.4 ���� java �ļ�... 10

1.5 ������Ŀ... 11

1.6 �������������... 12

�ڶ��� JFinalConfig. 13

2.1 ����... 13

2.2 configConstant(Constants me). 13

2.3 configRoute(Routes me). 14

2.4 configPlugin (Plugins me). 17

2.5 configInterceptor (Interceptors me). 17

2.6 configHandler (Handlers me). 18

2.7 afterJFinalStart()�� beforeJFinalStop(). 18

������ Controller. 19

3.1 ����... 19

3.2 Action. 19

3.3 getPara ϵ�з���... 19

3.4 getFile �ļ��ϴ�... 21

3.5 setAttr ����... 21

3.6 render ϵ�з���... 21

������ Interceptor. 23

4.1 ����... 23

4.2 Interceptor Ӧ��... 23

4.3 Interceptor ����... 24

4.4 ActionInvocation. 26

4.5 InterceptorStack. 26

������ ActiveRecord. 27

5.1 ����... 27

5.2 ActiveRecordPlugin. 27

5.3 Model 28

5.4 JFinal ���� Db + Record ģʽ... 29

5.5 ����ʽ����... 31

5.6 Cache. 32

5.7 Dialect �����ݿ�֧��... 32

5.8 ����������... 33

5.9 Oracle ֧��... 34

5.10 ������Դ֧��... 36

������ EhCachePlugin. 38

6.1 ����... 38

6.2 EhCachePlugin. 38

6.3 CacheInterceptor. 38

6.4 EvictInterceptor. 39

6.5 CacheKit. 39

6.6 ehcache.xml ���... 41

������ SpringPlugin. 41

7.1 ����... 41

7.2 SpringPlugin. 41

7.3 IocInterceptor. 42

�ڰ��� Validator. 43

8.1 ����... 43

8.2 Validator. 43

8.3 Validator ����... 43

�ھ��� FreeMarker ����... 44

9.1 ����... 44

9.2 FreeMarker ʾ��... 44

9.3 �� JFinal ����չ... 45

��ʮ�� JFinal �ܹ�����չ... 45

10.1 ����... 45

10.2 �ܹ�... 45

 

 

ÕªÒª

   JFinal �ǻ��� Java ���Ե����� WEB + ORM ������ܣ���������Ŀ���ǿ���Ѹ�١���

��������ѧϰ�򵥡�����ǿ��������������չ��Restful����ӵ�� Java �����������Ƶ�ͬʱ��ӵ�� ruby��python��php �ȶ�̬���ԵĿ���Ч�ʣ�Ϊ����Լ����ʱ�䣬ȥ�����ˡ����˺����� : )

    JFinal ��������Ҫ�ص㣺

l  MVC �ܹ�����ƾ��ɣ�ʹ�ü�

l  ��ѭ COC ԭ�������ã��� xml

l  ���� Db + Record ģʽ��������

l  ActiveRecord ֧�֣�ʹ���ݿ⿪�����¿���

l  �Զ������޸ĺ�� java �ļ��������������������� web server

l  AOP ֧�֣�����������������ǿ��

l  Plugin ��ϵ�ṹ����չ��ǿ

l  ����ͼ֧�֣�֧�� FreeMarker��JSP��Velocity

l  ǿ��� Validator ���У�鹦��

l  ������ȫ��ӵ�� struts2 ���󲿷ֺ��Ĺ���

l  ����� 218K�����޵���������

 

JFinal �ٷ���վ��http://www.jfinal.com

JFinal QQ Ⱥ: 222478625��196337924��326297041 JFinal �ٷ�΢��:

 

 


��һ�� ��������

1.1 ������Ŀ

   JFinal �Ƽ�ʹ�� Eclipse IDE for Java EE Developers ��Ϊ�����������������ӣ�

http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/indigo/SR2/eclipse-jee-i ndigo-SR2-win32.zip

l  ���� Dynamic Web Project

  

l  ������Ŀ������Ϣ

 

ע�⣺Target runtime һ��Ҫѡ��<None>

 

 

l  �޸� Default Output Folder���Ƽ����� WebRoot\WEB-INF\classes

 

�ر�ע�⣺�˴��� Default out folder ����Ҫ�� WebRoot\WEB-INF\classes Ŀ¼��ȫһ�²ſ���ʹ�� JFinal ���ɵ� Jetty ��������Ŀ��

 

l  �޸� Content directory���Ƽ����� WebRoot

 

ע�⣺�˴�Ҳ����ʹ��Ĭ��ֵ WebContent�� ����һ���е� WebRoot\WEB-INF\classes ����Ҫ�ij� WebContent\WEB-INF\classes ���ܶ�Ӧ�ϡ�

1.2 ���� JFinal ���ļ�

    �� jfinal-xxx.jar �� jetty-server-8.1.8.jar ��������Ŀ WEB-INF\lib �¼��ɡ�ע�⣺ jetty-server-8.1.8.jar �ǿ���ʱʹ�õ����л�����������������Ҫ���ļ���

1.3 �޸� web.xml

   ���������������� web.xml

 

 <filter>

  <filter-name>jfinal</filter-name>

 <filter-class>com.jfinal.core.JFinalFilter</filter-class>

  <init-param>

   <param-name>configClass</param-name>

  <param-value>demo.DemoConfig</param-value>

  </init-param>

 </filter>

<filter-mapping>

  <filter-name>jfinal</filter-name>   <url-pattern>/*</url-pattern>

</filter-mapping>

 

1.4 ���� java �ļ�

����Ŀ src Ŀ¼�´��� demo �������� demo ���´��� DemoConfig �ļ��� �������£�

package demo;

import com.jfinal.config.*; public class DemoConfig extends JFinalConfig {  public void configConstant(Constants me) {   me.setDevMode(true);

 }

 public void configRoute(Routes me) {   me.add("/hello", HelloController.class);

 }

 public void configPlugin(Plugins me) {}  public void configInterceptor(Interceptors me) {}  public void configHandler(Handlers me) {}

}

ע�⣺DemoConfig.java �ļ����ڵİ��Լ������ļ��������� web.xml �е� param-value ��ǩ�ڵ�������һ��(�ڱ����и�����Ϊ demo.DemoConfig)��

 

�� demo ���´��� HelloController ���ļ��� �������£�

 

package demo;

 import com.jfinal.core.Controller;

 public class HelloController extends Controller {

 public void index() {

   renderText("Hello JFinal World.");

  }

}

 

1.5 ������Ŀ

��������������ͼ��ʾ��

 

 

    ����Ҽ���� Java Application ��ѡ�� New �˵���½� Java Application ���������ͼ��ʾ��

 

���Ҳര���е� Main class �����������: com.jfinal.core.JFinal ����� Debug ��ť������

Ŀ������ͼ��ʾ��

 

 

1.6 �������������

��������ڵ�ַ��������: http://localhost/hello���������Ϊ Hello JFinal World ֤����Ŀ

��ܴ��ɡ��������� demo ʾ�����ڴ˴����أ�

http://code.google.com/p/jfinal/downloads/list

ע�⣺�� tomcat �¿�����������Ŀʱ����Ҫ��ɾ�� jetty-server-xxx.jar �����������������ͻ��Tomcat ������Ŀ��Ҫʹ�� TOMCAT-HOME/bin/startup.bat �� startup.sh ������ʹ��������ܵ�������ʽ����Ϊ�����������ʽ��Ҫ�õ� jetty-server-xxx.jar��

�ڶ��� JFinalConfig

2.1 ����

���� JFinal �� web ��Ŀ��Ҫ����һ���̳��� JFinalConfig ������࣬�������ڶ����� web

��Ŀ�������á�

JFinalConfig ������Ҫʵ��������󷽷���������ʾ��

 

public class DemoConfig extends JFinalConfig {

  public void configConstant(Constants me) {}   public void configRoute(Routes me) {}  public void configPlugin(Plugins me) {}

  public void configInterceptor(Interceptors me) {}   public void configHandler(Handlers me) {}

}

2.2 configConstant(Constants me)

�˷����������� JFinal ����ֵ���翪��ģʽ���� devMode �����ã�Ĭ����ͼ���� ViewType �����ã����´��������� JFinal �����ڿ���ģʽ����Ĭ����ͼ����Ϊ JSP��

 

public void configConstant(Constants me) {

  me.setDevMode(true);   me.setViewType(ViewType.JSP);

}

 

    �ڿ���ģʽ�£�JFinal ���ÿ������������棬�������������� Controller��Method �Լ�������Я���IJ�����JFinal ֧�� JSP��FreeMarker��Velocity ���ֳ�����ͼ��

2.3 configRoute(Routes me)

�˷����������� JFinal ����·�ɣ����´��������˽���/hello��ӳ�䵽 HelloController �����������ͨ�����µ����ã� http://localhost/hello ������ HelloController.index() ��������

http://localhost/hello/methodName �����ʵ� HelloController.methodName()������

 

public void configRoute(Routes me) {  me.add("/hello", HelloController.class);

}

 

 

Routes ����Ҫ����������������

public Routes add(String controllerKey, Class<? extends Controller>

controllerClass, String viewPath)

public Routes add(String controllerKey, Class<? extends Controller>

controllerClass)

    ��һ������ controllerKey ��ָ����ij�� Controller ����Ҫ��һ���ַ��������ַ���Ψһ��Ӧһ�� Controller��controllerKey ���ܶ�λ�� Controller���ڶ������� controllerClass �Ǹ� controllerKey ����Ӧ���� Controller������������ viewPath ��ָ�� Controller ���ص���ͼ�����

·��(�ò�������ϸ�ڽ��� Controller ����½��и���)���� viewPath δָ��ʱĬ��ֵΪ controllerKey��

JFinal ·�ɹ������±���

url ���

����Ŀ��

controllerKey

YourController.index()

controllerKey/method

YourController.method()

controllerKey/method/v0-v1

YourController.method()������ url ����ֵΪ��v0-v1

controllerKey/v0-v1

YourController.index()������ url ����ֵΪ��v0-v1

   �ӱ��п��Կ�����JFinal ����һ��ȷ�е� Action(Action ����� 3.2 ��)��Ҫʹ�� controllerKey

�� method ����ȷ��λ���� method ʡ��ʱĬ��ֵΪ index��urlPara ��Ϊ������ url ��Я������ֵ��urlPara ������һ��������ͬʱЯ�����ֵ��JFinal Ĭ��ʹ�ü�����-�����ָ����ֵ����

ͨ�� constants. setUrlParaSeparator(String)���÷ָ��������� Controller �п���ͨ�� getPara(int

index)�ֱ�ȡ����Щֵ��controllerKey��method��urlPara �������ֱ���ʹ����б����/���ָ���    ע�⣬controllerKey ����Ҳ���԰�����б����/��������/admin/article��������ʵ����ʵ���� struts2 �� namespace ���ܡ�

JFinal ������·�ɹ���֮�⻹�ṩ�� ActionKey ע�⣬���Դ���ԭ�й��������Ǵ���ʾ����

public class UserController extends Controller {

 @ActionKey("/login")  public void login() {   render("login.html");

 }

}

 

 

 

�ٶ� UserController �� controllerKey ֵΪ��/user������ʹ����@ActionKey(��/login��)ע����

��actionKey ��ԭ������/user/login����Ϊ����/login������ע�⻹������ actionKey ��ʹ�ü��Ż�

���ֵ��ַ�������/user/123-456����

��� JFinal Ĭ��·�ɹ������������󣬿����߻����Ը�����Ҫʹ�� Handler ���Ƹ��Ӹ�

�Ի���·�ɣ�����˼·������ Handler �иı��һ������ String target ��ֵ��

JFinal ·�ɻ����Խ��в�����ã���Դ��ģ�Ŷӿ����ر����ã������Ǵ���ʾ����

 public class FrontRoutes extends Routes {   public void config() {   add("/", IndexController.class);

   add("/blog", BlogController.class);

  }

}

 

public class AdminRoutes extends Routes {

 

 public void config() {

   add("/admin", AdminController.class);   add("/admin/user", UserController.class);

 

 }

 }

public class MyJFinalConfig extends JFinalConfig {  public void configRoute(Routes me) {   me.add(new FrontRoutes()); // �˶�·��   me.add(new AdminRoutes()); // ���·��

 }

 public void configConstant(Constants me) {}  public void configPlugin(Plugins me) {}  public void configInterceptor(Interceptors me) {}  public void configHandler(Handlers me) {}

}

 

    �������δ��룬FrontRoutes ����������ϵͳǰ��·�ɣ�AdminRoutes ������ϵͳ���·�ɣ� MyJFinalConfig.configRoute(��)��������ֺ��������·�ɺϲ�������ʹ�����ֲ�����ò���

������ MyJFinalConfig �ļ�����࣬���������ڴ��ģ�Ŷӿ������������ͬʱ�޸� MyJFinalConfig ʱ�İ汾��ͻ��

2.4 configPlugin (Plugins me)

�˷����������� JFinal �� Plugin�����´��������� C3p0 ���ݿ����ӳز���� ActiveRecord

���ݿ���ʲ����ͨ�����µ����ã�������Ӧ����ʹ�� ActiveRecord �dz�����ز������ݿ⡣

 

public void configPlugin(Plugins me) { loadPropertyFile("your_app_config.txt");

 C3p0Plugin c3p0Plugin = new C3p0Plugin(getProperty("jdbcUrl"),

getProperty("user"), getProperty("password"));

 me.add(c3p0Plugin);

 ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);  me.add(arp);

 arp.addMapping("user", User.class);

}

     JFinal ����ܹ�������Ҫ��չ��ʽ֮һ�����Է���ش��������Ӧ�õ���Ŀ��ȥ��

2.5 configInterceptor (Interceptors me)

�˷����������� JFinal �� Interceptor�����´�����������Ϊ AuthInterceptor �����������ڴ˴����õ���������������е�����������أ�����ʹ��@ClearInterceptor �� Controller �������

 

public void configInterceptor(Interceptors me) {

 

 me.add(new AuthInterceptor());

 }

     JFinal �� Interceptor �dz������� Struts2����ʹ�����������㣬Interceptor �������ȷ�Ϊ Global��Controller��Action ������Σ��������ϴ�����������Ϊȫ�֡�Controller �� Action ���� Interceptor ���ý��ں����½�����ϸ���ܡ�

2.6 configHandler (Handlers me)

�˷�����������JFinal��Handler�����´�����������ΪResourceHandler�Ĵ�������Handler

���Խӹ����� web ���󣬲���Ӧ��ӵ�����Ŀ���Ȩ�����Ժܷ����ʵ�ָ��߲�Ĺ�������չ��

 

public void configHandler(Handlers me) {

 

 me.add(new ResourceHandler());

 }

2.7 afterJFinalStart()�� beforeJFinalStop()

  JFinalConfig�е� afterJFinalStart()��beforeJFinalStop()��������������JFinalConfig�̳�����

���ǡ�JFinal ����ϵͳ������ɺ�ص� afterJFinalStart()����������ϵͳ�ر�ǰ�ص� beforeJFinalStop()�������������������Ժܷ��������Ŀ��������ر�ǰ�ÿ������л������

�������������ϵͳ�����󴴽������̻߳���ϵͳ�ر�ǰд�ػ��档

 

������ Controller

3.1 ����

Controller �� JFinal ������֮һ��������Ϊ MVC ģʽ�еĿ����������� JFinal �� Web Ӧ�õĿ�������Ҫ�̳и��ࡣController �Ƕ��� Action �����ĵص㣬����֯ Action ��һ�ַ�ʽ��һ�� Controller ���԰������ Action��Controller ���̰߳�ȫ�ġ�

3.2 Action

    Controller �Լ������ж���� public �޲η�����Ϊһ�� Action��Action ���������С��λ��

Action ���������� Controller ���������÷��������� public �ɼ�����û���βΡ�

 

public class HelloController extends Controller {

  public void index() {   renderText("�˷�����һ��action");

 

 }

  public void test() {   renderText("�˷�����һ��action");

 

 }

 }

    ���ϴ����ж��������� Action��HelloController.index()��HelloController.test()���� Controller

���ṩ�� getPara ϵ�з��� setAttr �����Լ� render ϵ�з����� Action ʹ�á�

3.3 getPara ϵ�з���

    Controller�ṩ��getParaϵ�з��������������л�ȡ������getParaϵ�з�����Ϊ�������͡�

��һ������Ϊ��һ���β�Ϊ String �� getPara ϵ�з�������ϵ�з����Ƕ�

HttpServletRequest.getParameter(String name) �� �� װ �� �� �� �� �� �� �� ת �� �� HttpServletRequest.getParameter(String name)���ڶ�������Ϊ��һ���β�Ϊ int �����βε� getPara ϵ�з�������ϵ�з�����ȥ��ȡ urlPara �������IJ���ֵ��getParaMap �� getParaNames �ֱ��Ӧ HttpServletRequest �� getParameterMap �� getParameterNames��

���似�ɣ���һ������Ϊ String ���͵Ľ���ȡ������ url ���ʺŹҲε���ֵ����һ������Ϊ int ���޲����Ľ���ȡ urlPara �еIJ���ֵ��     getPara ʹ�����ӣ�

��������

����ֵ

getPara(��title��)

����ҳ���������Ϊ��title������ֵ

getParaToInt(��age��)

����ҳ���������Ϊ��age���IJ���ֵ��תΪ int ��

getPara(0)

���� url �����е� urlPara �����ĵ�һ��ֵ����

http://localhost/controllerKey/method/v0-v1-v2 �������

������v0��

getParaToInt(1)

���� url �����е� urlPara �����ĵڶ���ֵ��ת����

int �ͣ��� http://localhost/controllerKey/method/2-5-9

������󽫷��� 5

getParaToInt(2)

�� http://localhost/controllerKey/method/2-5-N8 ���

���󽫷��� -8��ע�⣺Լ����ĸ N �� n ���Ա�ʾ��

�ţ���� urlParaSeparator Ϊ ��-�� ʱ�dz����á�

getPara()

���� url �����е� urlPara ����������ֵ���� http://localhost/controllerKey/method/v0-v1-v2 ���

���󽫷�����v0-v1-v2��

3.4 getFile �ļ��ϴ�

Controller �ṩ�� getFile ϵ�з���֧���ļ��ϴ����ر�ע�⣺����ͻ�������Ϊ multipart

request��form ����ʹ���� enctype="multipart/form-data"������ô�����ȵ��� getFile ϵ�з�����

��ʹ getPara ϵ�з���������������Ϊ multipart request ��Ҫͨ�� getFile ϵ�з��������������е����ݣ�����������

3.5 setAttr ����

    setAttr(String, Object)ת���� HttpServletRequest.setAttribute(String, Object)���÷������Խ��������ݴ��ݸ� View ���� View ����ʾ������

3.6 render ϵ�з���

render ϵ�з�������Ⱦ��ͬ���͵���ͼ�����ظ��ͻ��ˡ�JFinal Ŀǰ֧�ֵ���ͼ�����У�

FreeMarker��JSP��Velocity��JSON��File��Text��Html �ȵȡ����� JFinal ֧�ֵ���ͼ�����⣬

������ͨ���̳� Render ��������������չ��ͼ���͡�

    ͨ�������ʹ�� Controller.render(String)��������Ⱦ��ͼ��ʹ�� Controller.render(String)ʱ�� �� ͼ �� �� �� JFinalConfig.configConstant(Constants constants) �� �� �� �� constants. setViewType(ViewType)�������������÷���֧�ֵ� ViewType �У�FreeMarker��JSP��Velocity������������ʱ��ȱʡ����Ϊ FreeMarker��

    ������ JFinalConfig.configRoute(Routes routes) �������� Controller ӳ�����ã�

routes.add(��/user��, UserController.class, ��/path��)�� render(String view)ʹ�����ӣ�

��������

����

render(��test.html��)

��Ⱦ��Ϊ test.html ����ͼ������ͼ��ȫ·��

��/path/test.html��

render(��/other_path/test.html��)

��Ⱦ��Ϊ test.html ����ͼ������ͼ��ȫ·��

Ϊ��/other_path/test.html����������������/����ͷʱ��

���þ���·����

 

    ���� render ����ʹ�����ӣ�

��������

����

renderFreeMarker(��test.html��)

��Ⱦ��Ϊ test.html ����ͼ������ͼ����Ϊ

FreeMarker��

renderJsp(��test.html��)

��Ⱦ��Ϊ test.html ����ͼ������ͼ����Ϊ Jsp��

renderVelocity(��test.html��)

��Ⱦ��Ϊ test.html ����ͼ������ͼ����Ϊ Velocity��

renderJson()

������ͨ�� Controller.setAttr(String, Object)���õı���ת���� json ���ݲ���Ⱦ��

renderJson(��users��, userList)

����users��Ϊ�������� userList �е�����ת���� json ���ݲ���Ⱦ��

renderJson(user)

�� user ����ת���� json ���ݲ���Ⱦ��

renderJson(��{\��age\��:18}�� )

ֱ����Ⱦ json �ַ�����

renderJson(new 

String[]{��user��, ��blog��})

���� setAttr(��user��, user)�� setAttr(��blog��, blog)��

�õ�����ת���� json ����Ⱦ��ʹ�� setAttr ���õ��������Բ���ת��Ϊ json��

renderFile(��test.zip��);

��Ⱦ��Ϊ test.zip ���ļ���һ�������ļ�����

renderText(��Hello JFinal��)

��Ⱦ���ı�������Hello JFinal����

renderHtml(��Hello Html��)

��Ⱦ Html ������Hello Html����

renderError (404 , ��test.html��)

��Ⱦ��Ϊ test.html ���ļ�����״̬Ϊ 404��

renderError (500 , ��test.html��)

��Ⱦ��Ϊ test.html ���ļ�����״̬Ϊ 500��

renderNull()

����Ⱦ��������ͻ��˷������ݡ�

render(new XmlRender())

ʹ���Զ���� XmlRender ����Ⱦ��

ע�⣺

1��IE ��֧�� contentType Ϊ application/json,�� ajax �ϴ��ļ���ɺ󷵻� json ʱ IE ��ʾ�����ļ�,����취��ʹ�ã�render(new JsonRender(params).forIE())��

2���� renderError �������⣬�ڵ��� render ϵ�еķ�������򲢲����������أ������Ҫ����������Ҫʹ�� return ��䡣��һ�� action �ж�ε��� render ����ֻ�����һ����Ч��

 

 

 

������ Interceptor

4.1 ����

    Interceptor �� JFinal AOP ��ʵ�ַ�ʽ��ͨ��ʵ�� Interceptor �ӿ��Լ�ʹ��@Before

annotation ����ϸ���ȵؽ������á�Interceptor �����̰߳�ȫ�ģ��̰߳�ȫ��������Ҫ�̳�

PrototypeInterceptor ��ʵ�֡�

4.2 Interceptor Ӧ��

Interceptor �ӿڽ�������һ������ void intercept(ActionInvocation ai)�����´��뽫�ڱ�����

���� Action ǰ������һ���ı�������̨��

 

 

import com.jfinal.aop.Interceptor;

 import com.jfinal.core.ActionInvocation;  public class DemoInterceptor implements Interceptor {  public void intercept(ActionInvocation ai) {    System.out.println("Before action invoking");    ai.invoke();

  System.out.println("After action invoking");

  }

 }     ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½Ê¾ï¿½ï¿½JFinal Interceptor ���Ժܷ������ action ����ǰ��������������ʵ�� AOP��

4.3 Interceptor ����

���������ù�����������Global ����Controller ����Action ����Global ������������������ Action �������أ�Controller �����������Ը� Controller ������ Action �������أ�Action �����������Ը� Action �������ء�

Global ���������� JFinalConfig.configInterceptor(Interceptors me)�������á�Controller ����

����ʹ��@Before annotation������Controller�ඨ��ǰ�������á�Action��������ʹ��@Before annotation ������ Action ����ǰ�������á�

 

    ����Ϊ Controller �� Action ������������ʾ����

@Before(DemoInterceptor.class) // ����һ��Controller����������� public class HelloController extends Controller {

 @Before(AaaInterceptor.class)  public void index() {

  renderText("����һ��action�����������");

 }

 @Before({AaaInterceptor.class, BbbInterceptor.class})  public void test() {

  renderText("���ö��action�����������");

 }

 @ClearInterceptor  public void login() {

  renderText("�����һ����(Controller��)��������");

 }

 @ClearInterceptor(ClearLayer.ALL)  public void clearAllLayers() {

  renderText("��������(Global����Controller��)��������");

 }

}

    ClearInterceptor Ĭ�Ͻ������һ�������������Action ������һ��Ϊ Controller ���� Controller ������һ��Ϊ Global ���������ɾ���༶������������Ϊ ClearInterceptor �������

ClearLayer.ALL��

    ����Ϊ Global ������������ʾ����

 public class DemoConfig extends JFinalConfig {   public void configInterceptor(Interceptors me) {

  // �˴����õ�����������������Action

   me.add(new AaaInterceptor());

  }

}

 

4.4 ActionInvocation

    ActionInvocation ��Ϊ Interceptor �ӿ� intercept �����е�Ψһ�������ṩ�˺ܶ�����ķ����Ա�����������ʹ�á�

����Ϊ ActionInvocation �еķ�����

����

����

void invoke()

�������ε��ã�������ʣ�µ��������� Action

Controller getController()

��ȡ���� Action ���������� Controller

String getActionKey()

��ȡ���� Action ���õ� action key ֵ

String getControllerKey()

��ȡ���� Action ���õ� controller key ֵ

Method getMethod()

��ȡ���� Action ���õ� Method ����

String getMethodName()

��ȡ���� Action ���õ� Method ���������

String getViewPath()

��ȡ���� Action ���õ���ͼ·��

4.5 InterceptorStack

    InterceptorStack �ɽ������������ϳ�һ��������������Ҫ��ijһ���������ظ�����ʹ�õ�ʱ����Լ������ô�������ʾ���������£�

public class ManagerInterceptor extends InterceptorStack {  public void config() {

  addInterceptors(new AuthInterceptor(), new DemoInterceptor());

 }

}

    ���ϴ��뽫�������������Ϊ��һ������������Ϻ������������ͨ���������÷�����ȫһ������ȻΪ��@Before(ManagerInterceptor.class)

 

 

 

������ ActiveRecord

5.1 ����

    ActiveRecord �� JFinal �����ĵ���ɲ���֮һ��ͨ�� ActiveRecord ���������ݿ⣬������ؼ��ٴ��������������������Ч�ʡ�

5.2 ActiveRecordPlugin

ActiveRecord ����Ϊ JFinal �� Plugin �����ڵģ�����ʹ��ʱ��Ҫ�� JFinalConfig ������

ActiveRecordPlugin��

    ������ Plugin ����ʾ������

public class DemoConfig extends JFinalConfig { public void configPlugin(Plugins me) {

 C3p0Plugin cp = new C3p0Plugin("jdbc:mysql://localhost/db_name",

"userName", "password");  me.add(cp);

 ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);  me.add(arp);  arp.addMapping("user", User.class);

 arp.addMapping("article", "article_id", Article.class);

}

}

���ϴ������������������C3p0Plugin �� ActiveRecordPlugin��ǰ���� c3p0 ����Դ����������� ActiveRecrod ֧�ֲ����ActiveReceord �ж����� addMapping(String tableName, Class<? extends Model> modelClass>)�������÷������������ݿ������ Model ��ӳ���ϵ��

���⣬���ϴ����� arp.addMapping(��user��, User.class)������������ΪĬ��Ϊ��id���������

������Ϊ ��user_id������Ҫ�ֶ�ָ�����磺arp.addMapping(��user��, ��user_id��, User.class)��

5.3 Model

    Model �� ActiveRecord ������Ҫ�����֮һ�����䵱 MVC ģʽ�е� Model ���֡�������

Model ����ʾ�����룺

 

public class User extends Model<User> {

  public static final User dao = new User();

}

 

���ϴ����е� User ͨ���̳� Model��������ӵ�е��ڶ෽��IJ������ݿ�ķ������� User �������� dao ��̬������Ϊ�˷����ѯ����������ģ��ö��󲢲��DZ���ġ����� ActiveRecord

�� Model ���趨�����ԣ����趨�� getter��setter ���������� XML ���ã����� Annotation ���ã����󽵵��˴�������

����Ϊ Model ��һЩ�����÷���

// ����name����ΪJames,age����Ϊ25��User�������ӵ����ݿ�

new User().set("name", "James").set("age", 25).save(); 

// ɾ��idֵΪ25��User

User.dao.deleteById(25);

 

// ��ѯidֵΪ25��User����name���Ը�ΪJames�����µ����ݿ�

User.dao.findById(25).set("name", "James").update();

 

// ��ѯidֵΪ25��user, �ҽ���ȡname��age�����ֶε�ֵ

User user = User.dao.findById(25, "name, age");

 

// ��ȡuser��name����

String userName = user.getStr("name");

 

// ��ȡuser��age����

Integer userAge = user.getInt("age");

 

// ��ѯ�����������18���user

List<User> users = User.dao.find("select * from user where age>18"); 

// ��ҳ��ѯ�������18��user,��ǰҳ��Ϊ1,ÿҳ10��user

Page<User> userPage = User.dao.paginate(1, 10, "select *", "from user where age > ?", 18);

 

�ر�ע�⣺User �ж���� public static final User dao ������ȫ�ֹ����ģ�ֻ���������ݿ��ѯ�������������ݳ��ض������ݳ�����Ҫʹ�� new User().set(��)��ʵ�֡�

5.4 JFinal ���� Db + Record ģʽ

Db �༰�����׵� Record �࣬�ṩ���� Model ��֮���Ϊ�ḻ�����ݿ�������ܡ�ʹ��

Db �� Record ��ʱ����������ݿ������ӳ�䣬Record �൱��һ��ͨ�õ� Model������Ϊ Db +

Record ģʽ��һЩ�����÷���

// ����name����ΪJames,age����Ϊ25��record�������ӵ����ݿ�

Record user = new Record().set("name", "James").set("age", 25);

Db.save("user", user);

 

// ɾ��idֵΪ25��user���еļ�¼

Db.deleteById("user", 25);

 

// ��ѯidֵΪ25��Record����name���Ը�ΪJames�����µ����ݿ� user = Db.findById("user", 25).set("name", "James");

Db.update("user", user);

 

// ��ѯidֵΪ25��user, �ҽ���ȡname��age�����ֶε�ֵ

user = Db.findById("user", 25, "name, age");

 

// ��ȡuser��name����

String userName = user.getStr("name");

 

// ��ȡuser��age����

Integer userAge = user.getInt("age");

 

// ��ѯ�����������18���user

List<Record> users = Db.find("select * from user where age > 18"); 

// ��ҳ��ѯ�������18��user,��ǰҳ��Ϊ1,ÿҳ10��user

Page<Record> userPage = Db.paginate(1, 10, "select *", "from user where age > ?", 18);

 

      ����Ϊ������ʾ����

boolean succeed = Db.tx(new IAtom(){  public boolean run() throws SQLException {

  int count = Db.update("update account set cash = cash - ? where id = ?", 100, 123);

  int count2 = Db.update("update account set cash = cash + ? where id = ?", 100, 456);

  return count == 1 && count2 == 1;

 }});

}

 

    �����������ݿ���²�����һ��������ִ�У����ִ�й����з����쳣���� invoke()�������� false�����Զ��ع�������

5.5 ����ʽ����

    ActiveRecord ֧������ʽ�����������´���������ʽ����ʾ����

 

// ������Ϊʾ��, ��δ�ϸ����˻�״̬��ҵ���߼�

@Before(Tx.class) public void trans_demo() {

 // ��ȡת�˽��

 Integer transAmount = getParaToInt("transAmount");

 // ��ȡת���˻�id

 Integer fromAccountId = getParaToInt("fromAccountId");

 // ��ȡת���˻�id

 Integer toAccountId = getParaToInt("toAccountId");

 // ��ȡת���˻�����

 Account fromAccount = Account.dao.findById(fromAccountId);

 // ��ȡת���˻�����

 Account toAccount = Account.dao.findById(toAccountId);

 // ת������

 fromAccount.set("cash", fromAccount.getInt("cash") - transAmount).update();

 // ת�����

 toAccount.set("cash", toAccount.getInt("cash") + transAmount).update();

}

 

���ϴ����У���������һ�� Tx ��������Ϊ action ����������֧�֡�����֮�� ActiveRecord

���䱸��TxByRegex��TxByActionKeys��TxByActionMethods���ֱ�֧��regex(����)��actionKeys��

actionMethods ����ʽ����������ʾ�����룺

 

public void configInterceptor(Interceptors me) {

          me.add(new TxByRegex(".*save.*"));

me.add(new TxByActionKeys("/cash/trans", "/other"));

 

me.add(new TxByActionMethods("save", "update"));

 }

    �����е� TxByRegex ��������ͨ�������������ʽ�� action �������أ��� actionKey ������ƥ���Ͻ���������TxByActionKeys ���Զ�ָ���� actionKey �������ز��������� TxByActionMethods ���Զ�ָ���� method �������ز���������

ע�⣺MySql ���ݿ����������Ϊ InnoDB ����ʱ��֧������MyISAM ����֧������

5.6 Cache

    ActiveRecord ����ʹ�û����Դ��������ܣ����´����� Cache ʹ��ʾ����

        public void list() {

           List<Blog> blogList = Blog.dao.findByCache("cacheName", "key",

"select * from blog");     setAttr("blogList", blogList).render("list.html");

        }

     ���� findByCache �����е� cacheName ��Ҫ�� ehcache.xml �������磺 <cache name="cacheName" ��> �� �� �� Model.paginateByCache(��) �� Db.findByCache(��) �� Db.paginateByCache(��)�������ṩ�� cache ֧�֡���ʹ��ʱ��ֻ�贫�� cacheName��key �Լ��� ehccache.xml ���������Ӧ�� cacheName �Ϳ����ˡ�

5.7 Dialect �����ݿ�֧��

    Ä¿Ç° ActiveRecordPlugin �ṩ�� MysqlDialect��OracleDialect��AnsiSqlDialect ʵ���ࡣ

MysqlDialect �� OracleDialect �ֱ�ʵ�ֶ� Mysql �� Oracle ��֧�֣�AnsiSqlDialect ʵ�ֶ�����

ANSI SQL ���ݿ��֧�֡����������ݿ� Dialect �����ô��룺

public class DemoConfig extends JFinalConfig { public void configPlugin(Plugins me) {

 ActiveRecordPlugin arp = new ActiveRecordPlugin(��);  me.add(arp);  // ����Postgresql����

  arp.setDialect(new PostgresqlDialect());

}

}

5.8 ����������

JFinal ActiveRecord ��Ȼ֧�ֱ�����������������Ҫѧϰ�µĶ�����JFinal �ƴ�Ϊ����ʤ���С�������������Ҫ�����ַ�ʽ��һ��ֱ��ʹ�� sql �õ��������ݣ������� Model �����ӻ�ȡ�������ݵķ�����

�ٶ������������ݿ����user��blog������ user �� blog ��һ�Զ��ϵ��blog ����ʹ�� user_id

������ user �������´�����ʾʹ�õ�һ�ַ�ʽ�õ� user_name��

public void relation() {

String sql = "select b.*, u.user_name from blog b inner join user u on b.user_id=u.id where b.id=?";

Blog blog = Blog.dao.findFirst(sql, 123); String name = blog.getStr("user_name");

}

 

���´�����ʾ�ڶ��ַ�ʽ�� Blog �л�ȡ������� User �Լ��� User �л�ȡ������� Blog��

public class Blog extends Model<Blog>{  public static final Blog dao = new Blog();

 

 public User getUser() {   return User.dao.findById(get("user_id"));

 }

} public class User extends Model<User>{  public static final User dao = new User();

 

 public List<Blog> getBlogs() { return Blog.dao.find("select * from blog where user_id=?", get("id"));

 }

}

 

 

 

5.9 Oracle ֧��

Oracle ���ݿ����һ���������ԣ�JFinal �����Щ�����Խ�����һЩ�����֧���Է������ Oracle ʹ���ߡ�������һ�������� Oracle ����ʾ����

 

public class DemoConfig extends JFinalConfig { public void configPlugin(Plugins me) {

 C3p0Plugin cp = new C3p0Plugin(����);

  //����Oracle����

  cp. setDriverClass("oracle.jdbc.driver.OracleDriver");  me.add(cp);

 ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);  me.add(arp);

 // ����Oracle����

  arp.setDialect(new OracleDialect());

  // ����������(�ֶ���)��Сд��������������

  arp.setContainerFactory(new CaseInsensitiveContainerFactory()); arp.addMapping("user", "user_id", User.class);

}

}

����Oracle���ݿ���Զ���������(�ֶ���)ת���ɴ�д��������Ҫ�ֶ�ָ��������Ϊ��д��

�磺arp.addMaping(��user��, ��ID��, User.class)��������� ActiveRecord �����������ֶ������Ĵ�

Сд�����п���ͨ������ CaseInsensitiveContainerFactory ���ﵽ������������ã��� arp.addMaping(��user��, ��ID��, User.class)������Ҫ�ˡ�

���⣬Oracle ��δֱ��֧������������JFinal Ϊ���ṩ�˱�ݵĽ��������Ҫ�� Oracle ֧

���Զ�������Ҫ��Ϊ������һ�Ǵ������У������� model ��ʹ��������У�����취���£� 1��ͨ�����°취�������У�������������Ϊ��MY_SEQ

         CREATE SEQUENCE MY_SEQ

           INCREMENT BY 1

 MINVALUE 1

           MAXVALUE 9999999999999999

           START WITH 1

 CACHE 20;

 

 

    2���� YourModel.set(��)��ʹ�����洴��������

        // ����User��ʹ������

        User user = new User().set("id", "my_seq.nextval").set("age", 18); user.save();

        // ��ȡidÖµ

         Integer id = user.get("id");

���е�ʹ�úܼ򵥣�ֻ��Ҫ yourModel.set(������, ������)�Ϳ����ˡ�

5.10 ������Դ֧��

ActiveRecordPlugin ��ͬʱ֧�ֶ�����Դ���෽�ԡ��໺�桢�����񼶱�����ԣ���ÿ�� ActiveRecordPlugin �ɽ��б˴˶��������á�����֮ JFinal ����ͬʱʹ�ö�����Դ�����ҿ�

�������������Դ���ö����ķ��ԡ����桢���񼶱�ȡ�

   ��ʹ�ö�����Դʱ��ֻ��Ҫ��ÿ�� ActiveRecordPlugin ָ��һ�� configName ���ɣ������Ǵ���ʾ����

public void configPlugin(Plugins me) {

// mysql ����Դ

C3p0Plugin dsMysql = new C3p0Plugin(��); me.add(dsMysql);

  

// mysql ActiveRecrodPlugin ʵ������ָ��configNameΪ mysql

ActiveRecordPlugin arpMysql = new ActiveRecordPlugin("mysql", dsMysql); me.add(arpMysql); arpMysql.setCache(new EhCache()); arpMysql.addMapping("user", User.class);

  

// oracle ����Դ

C3p0Plugin dsOracle = new C3p0Plugin(��); me.add(dsOracle);

  

// oracle ActiveRecrodPlugin ʵ������ָ��configNameΪ oracle

ActiveRecordPlugin arpOracle = new ActiveRecordPlugin("oracle", dsOracle); me.add(arpOracle); arpOracle.setDialect(new OracleDialect()); arpOracle.setTransactionLevel(8); arpOracle.addMapping("blog", Blog.class);

}

 

���ϴ��봴���˴������� ActiveRecordPlugin ʵ�� arpMysql �� arpOrace���ر�ע�ⴴ��ʵ����ͬʱָ���� configName �ֱ�Ϊ mysql �� oracle��arpMysql �� arpOracle �ֱ�ӳ���˲�ͬ�� Model�������˲�ͬ�ķ��ԡ����� Model ��ʹ�ã���ͬ�� Model ���Զ��ҵ��������� ActiveRecrodPlugin ʵ���Լ�������ý������ݿ���������� Db + Record ��ʹ�ã���Ҫʹ�� Db.use(cnfigName)�����õ����ݿ��������Ȼ��Ϳ��Խ������ݿ�����ˣ������Ǵ���ʾ����

 

// ��ѯ dsMysql����Դ�е� user

List<Record> users = Db.use("mysql").find("select * from user");

// ��ѯ dsOracle����Դ�е� blog

List<Record> blogs = Db.use("oracle").find("select * from blog");

 

    �������д��룬�ֱ�ͨ�� configName Ϊ mysql��oracle �õ����Ե����ݿ��������Ȼ��Ϳ�����ͬ��������ȫһ���ķ�ʽ��ʹ�����ݿ���� API �ˡ�����֮������ Db + Record ��˵��������Դ��ȵ�����Դ��������һ�� Db.use(configName)������ API ʹ�÷�ʽ��ȫһ����

    ע�����ȴ����� ActiveRecrodPlugin ʵ�������Ϊ������Դ������ʡ�� configName�����ȴ����� ActiveRecrodPlugin ʵ���е����ý�Ĭ�ϳ�Ϊ�����ã����⻹����ͨ������ configName Ϊ DbKit.MAIN_CONFIG_NAME ���������������á�

 

 

������ EhCachePlugin

6.1 ����

    EhCachePlugin �� JFinal ���ɵĻ�������ͨ��ʹ�� EhCachePlugin �������ϵͳ�IJ��������ٶȡ�

6.2 EhCachePlugin

EhCachePlugin ����Ϊ JFinal �� Plugin �����ڵģ�����ʹ��ʱ��Ҫ�� JFinalConfig ������

EhCachePlugin�������� Plugin ����ʾ�����룺

public class DemoConfig extends JFinalConfig { public void configPlugin(Plugins me) { me.add(new EhCachePlugin());

}

}

6.3 CacheInterceptor

    CacheInterceptor ���Խ� action ��������ȫ�������������´�������ʱ��� cache ������ֱ��ʹ�����ݲ� render��������ȥ���� action�����÷���ʹ action ��ȫ���� cache ��ش�����

��Ⱦ�����弴�ã�������ʾ�����룺

@Before(CacheInterceptor.class) public void list() {

 List<Blog> blogList = Blog.dao.find("select * from blog");  User user = User.dao.findById(getParaToInt());  setAttr("blogList", blogList);  setAttr("user", user);  render("blog.html");

}

    �����е��÷���ʹ�� actionKey ��Ϊ cacheName����ʹ��֮ǰ��Ҫ�� ehcache.xml �������� actionKey ������ cache �磺<cache name="/blog/list" ��>��ע�� actionKey ��Ϊ cacheName ����

ʱб����/������ʡ�ԡ����� CacheInterceptor �������� CacheName ע�����ʹ�ã��Դ���ȡ��Ĭ�ϵ� actionKey ��Ϊ actionName��������ʾ�����룺

@Before(CacheInterceptor.class)

@CacheName("blogList") public void list() {

 List<Blog> blogList = Blog.dao.find("select * from blog");  setAttr("blogList", blogList);  render("blog.html");

}

�����÷���Ҫ�� ehcache.xml ��������Ϊ blogList �� cache �磺<cache name="blogList" ��>��

6.4 EvictInterceptor

    EvictInterceptor ���Ը��� CacheName ע���Զ�������档������ʾ�����룺

@Before(EvictInterceptor.class)

@CacheName("blogList") public void update() {  getModel(Blog.class).update();  redirect("blog.html");

}

 

    �����е��÷������ cacheName Ϊ blogList �Ļ������ݣ�������ϵ� CacheInterceptor ���Զ����� cacheName Ϊ blogList �Ļ������ݡ�

6.5 CacheKit

    CacheKit �ǻ�����������࣬������ʾ�����룺

public void list() {

 List<Blog> blogList = CacheKit.get("blog", "blogList");  if (blogList == null) {

  blogList = Blog.dao.find("select * from blog");

  CacheKit.put("blog", "blogList", blogList);

 }

 setAttr("blogList", blogList);  render("blog.html");

}

    CacheKit ������Ҫ������������get(String cacheName, Object key)��put(String cacheName, Object key, Object value)��get �����Ǵ� cache ��ȡ���ݣ�put �����ǽ����ݷ��� cache������ cacheName �� ehcache.xml �е�<cache name="blog" ��>name ����ֵ��Ӧ������ key ��ָȡֵ��

���� key������ value �DZ���������ݡ�

    ���´����� CacheKit �����ص� CacheKit.get(String, String, IDataLoader)����ʹ��ʾ����

 

public void list() {

 List<Blog> blogList = CacheKit.get("blog", "blogList", new IDataLoader(){   public Object load() {

   return Blog.dao.find("select * from blog");

 }});

 setAttr("blogList", blogList);  render("blog.html");

}

 

    CacheKit.get �����ṩ��һ�� IDataLoader �ӿڣ��ýӿ��е� load()�����ڻ���ֵ������ʱ�Żᱻ���á��÷����ľ�����������ǣ������� cacheName=blog �Լ� key=blogList Ϊ����ȥ����ȡ���ݣ�������������ݴ��ھ�ֱ�ӷ��ظ����ݣ������������ IDataLoader.load()��������ȡ���ݡ�

6.6 ehcache.xml ���

    EhCache ��ʹ����Ҫ�� ehcache.xml �����ļ�֧�֣��������ļ��������˺ܶ� cache �ڵ㣬ÿ�� cache �ڵ������һ�� name ���ԣ����磺<cache name="blog" ��>���������� CacheKit

ȡֵ������ġ������������� eternal��           overflowToDisk��timeToIdleSeconds�� timeToLiveSeconds ��� EhCache �ٷ��ĵ���

 

������ SpringPlugin

7.1 ����

    SpringPlugin ���� Spring ���ϵIJ����ͨ��ʹ�� SpringPlugin ���������� Spring framework

���ϡ�

7.2 SpringPlugin

SpringPlugin ����Ϊ JFinal �� Plugin �����ڵģ�����ʹ��ʱ��Ҫ�� JFinalConfig ������

SpringPlugin�������� Plugin ����ʾ�����룺

public class DemoConfig extends JFinalConfig { public void configPlugin(Plugins me) { me.add(new SpringPlugin());

}

}

 

    ������ SpringPlugin ����ʱδָ�����췽���е��βΣ� SpringPlugin ���Զ�ȥ WebRoot/WEB-INF Ŀ¼��Ѱ�� applicationContext.xml ��Ϊ�����ļ����г�ʼ������������ͨ�������������췽��ָ�������ļ��� ApplicationContext ����

7.3 IocInterceptor

    IocInterceptor ���� action �������������ע�룬������ʾ�����룺

@Before(IocInterceptor.class) public class BlogController extends Controller {  private Integer id;

@Inject.BY_NAME  private BlogService blogService;  public void index() {   blogService.doService();   render("index.html");

 }

}

 

    �������� blogService ���������ƽ���ע�롣ע��@Inject.BY_NAME ������������ע�룬

@Inject.BY_TYPE �����ͽ���ע�롣��ָ��ע������ʱ���������ע�롣

�ڰ��� Validator

8.1 ����

    Validator �� JFinal ��������� Validator �����ṩ�˷dz������У�鷽����ѧϰ�òµ¥£ï¿½Ê¹ï¿½Ã·ï¿½ï¿½ã¡£

8.2 Validator

    Validator ����ʵ���� Interceptor �ӿڣ�������Ҳ��һ�������������÷�ʽ����������ȫһ���������� Validator ʾ����

public class LoginValidator extends Validator {  protected void validate(Controller c) {

  validateRequiredString("name", "nameMsg", "�������û���");   validateRequiredString("pass", "passMsg", "����������");

 }

 protected void handleError(Controller c) {   c.keepPara("name");

  c.render("login.html");

 }

}

    protected void validator(Controller c)�����п��Ե��� validateXxx(��)ϵ�з������к��У�飬protected void handleError(Controller c)�����п��Ե��� c.keepPara(��)�������ύ��ֵ�ٴ�

��ҳ���Ա㱣��ԭ�������ֵ�������Ե��� c.render(��)������������Ӧ��ҳ�档ע�� handleError(Controller c)ֻ����У��ʧ��ʱ�Ż���á�

8.3 Validator ����

    Validator ���÷�ʽ����������ȫһ�������������룺

 public class UserController extends Controller {

  @Before(LoginValidator.class) // ���÷�ʽ��������һ��  public void login() {

  }

}

�ھ��� FreeMarker ����

9.1 ����

JFinal Ĭ��ʹ�� FreeMarker ��Ϊ View��Ϊ��ʹ eclipse jee ����ȷʶ�� html������Ĭ��ʹ

����.html����Ϊ FreeMarker ��ͼ�ļ�����չ��(ԭΪ��.ftl��)��

�����Ҫʹ�� JSP ��ΪĬ����ͼ��Ҫ�� configConstant(Constants me)�����н������ã���

�������ã�

 

public void configConstant(Constants me) {

  me.setDevMode(true);   me.setViewType(ViewType.JSP);

}

 

9.2 FreeMarker ʾ��

    ���´���Ϊ FreeMarker ����ʹ�õ�ָ�����ֵ:

<table>

<#list userList as user>

<tr>

<td>${user.name}</td>

<td>${user.age}</td>

<td>${user.email}</td>

</tr>

  </#list>

</table>

     ���ϴ��뽫 userList �е� user ����ѭ�������

9.3 �� JFinal ����չ

  ����ͨ�� FreeMarkerRender.getConfiguration().setSharedVariable(��myKit��, new MyKit())Ϊ FreeMarker ���ù��������࣬�� view ��ʹ�� ${myKit.method(para)}��

��ʮ�� JFinal �ܹ�����չ

10.1 ����

JFinal ����΢�ں�ȫ��λ��չ�ܹ���ȫ��λ��ָ����չ��ʽ�ڿռ��ϵı�����ʽ��JFinal �� Handler��Interceptor��Controller��Render��Plugin ��󲿷���ɡ����½��򵥽��ܴ˼ܹ��Լ����ڴ˼ܹ�������һЩ��Ϊ���õ���չ��

10.2 �ܹ�

   JFinal ����ܹ�ͼ���£�

 

 

���� ����

 

JFinal �ٷ���վ��http://www.jfinal.com

JFinal QQ Ⱥ: 222478625��196337924��326297041 JFinal �ٷ�΢��: