`
hulianwang2014
  • 浏览: 695666 次
文章分类
社区版块
存档分类
最新评论
  • bcworld: 排版成这样,一点看的欲望都没有了
    jfinal

jfinal notes(2)

 
阅读更多
基于JFinal 的web项目需要创建一个 继承自 JFinalConfig类的 子类 ,该类用 于对整个 web项目进行配置 项目进行配置 。
JFinalConfig 子类需要实现 五个抽象方法 ,如:
public classDemoConfig extends JFinalConfig {
public void configConstant(Constantsme) {}
public void configRoute(Routes me) {}
public void configPlugin(Plugins me) {}
public void configInterceptor(Interceptors me) {}
public void configHandler(Handlers me) {}
}

configConstant
此方法用来配置 JF inal 常量 值,如开发模式 devMode 的配置,默认 视 图类型 ViewType 的配置 的配置 ,如下 代码 配置了 JFinal 运行在开发模式下且默认视图 类型为 JSP:
public void configConstant(Constants me) {
me.setDevMode(true);
me.setViewType(ViewType.JSP);
}


在开发模式下 ,JFinal会对每次 请求输出报告,如本会对每次 请求输出报告,如本请求的 Controller、 Method 以及请求所携带的参数。 以及请求所携带的参数。JFinal 支持 JSP 、 FreeMarker、Velocity三种常 用视图 。
configRoute
此方法用来配置 JF inal 访问 路由 ,如下 代码 配置了 将 ”/hello” 映射到 HelloController 这个控制器 , 通过以下的配置,http://localhost/hello将访问HelloController.index()方法,而
http://localhost/hello/other将访问到HelloController.other()方法.
字符串与控制类的映射是:
public void configRoute(Routes me) {
me.add("/hello", HelloController.class);
}
Routes 类主要 有如下 两个 方法:
public Routes add(String controllerKey, Class<?extendsController> controllerClass, String viewPath)
public Routes add(String controllerKey, Class<? extends Controller> controllerClass)


第一个参数 controllerKey是指访问某个 Controller所需要的一个字符串 ,该 字符串唯一对应个 Controller,controllerKey仅能定位到 仅能定位到 Controller。第二个参 数 controll er Class 是该 controllerKey所对应 到的 Controller。第三个参数 view Path 是指 该 Controller返回的视图 的相对路径。当 view Path未指定时默认值为 controllerKey。
1.当url是http://localhost/controllerKey时,调用的是对应控制类的index()方法;
当需要传参数时,url这样写:http://localhost/controllerKey/a-b-c,参数之间用中横线分开,
index()方法中调用getPara(i)得到参数,i是参数对应的下标,例如a的下标是0,b的下标是1,c的下标是2.
2.当url是http://localhost/controllerKey/method时,调用的是对应控制类的method()方法;
3.
JFinal 在以上路由 规则之外 还提供了 ActionKey注解, 可以打破 原有 规则, 以下是代码示例 :
public class HelloController extends Controller{
@ActionKey("second")
public void second(){
System.out.println("0="+getPara(0));
System.out.println("1="+getPara(1));
System.out.println("2="+getPara(2));
renderText("yjw");
}
}
这样url可以写成http://localhost/second/1-2-3,不用写控制类的映射了。
4.
如果以上所有路由规则都不能满足需求,开发者还可根据要使用 Handler定制更加个性化的路由,大体思就是在Handl er 中改变第一个参数 String target的值。
分享到:
评论

相关推荐

    Final IK 最新版2.1

    For the full history of release notes, see FinalIK Change Log.pdf in the package. Upgrade Guide - MAKE A BACKUP! Open a new scene, delete “Plugins/RootMotion” and reimport. Also reimport ...

    Final IK.zip

    Please see the Release Notes for the full list of update details. Final-IK 1.8 is fully compatible with PuppetMaster 0.8 and Unity 5/2017/2018/2019(beta) versions. What can I do with Final IK? ...

    Final+IK+1.9.unitypackage

    The final Inverse Kinematics solution for ...Please see the Release Notes for the full list of update details. Final IK 1.9 is fully compatible with PuppetMaster 0.9 and Unity 2017/2018/2019 versions.

    Final IK 1.9.unitypackage

    For the full history of release notes, see FinalIK Change Log.pdf in the package. Upgrade Guide - MAKE A BACKUP! Open a new scene, delete “Plugins/RootMotion” and reimport. Also reimport ...

    Final IK 1.9 当前时间最新版本

    Update (1.9): Version 1.9 brings many ...Please see the Release Notes for the full list of update details. Final IK 1.9 is fully compatible with PuppetMaster 0.9 and Unity 2017/2018/2019 versions.

    Unity Final IK v2.0版本 IK骨骼动画插件

    仅供学习使用,商用请购买正版 ...Please see the Release Notes for the full list of update details. Final IK 2.0 is fully compatible with PuppetMaster 1.0 and Unity 2017/2018/2019/2020 versions.

    Final IK v2.0 IK骨骼动画插件2020年10月15日最新版

    For the full history of release notes, see FinalIK Change Log.pdf in the package. Upgrade Guide - MAKE A BACKUP! Open a new scene, delete “Plugins/RootMotion” and reimport. Also reimport ...

    SD Specifications_Part_1_Physical_Layer_Specification_Ver3.00_Final_090416.pdf

    SD Specifications_Part_1_Physical_Layer_Specification_Ver3.00_Final_090416

    Lazarus1995#Dc-Notes#常见关键字问题1

    1. final的关键字提高了性能,JVM和java应用会缓存final变量 2. final变量可以在多线程环境下保持线程安全 3. 使用final的关键字提

    osm-notes-export

    用法在http://planet.openstreetmap.org/notes上下载最新的笔记转储使用以下命令解压缩文件: bzip2 -dk planet-notes-latest.osn.bz2 运行npm install并执行以下操作: node app/index.js \ --file planet-notes-...

    nmap 扫描应用(英文版)

    Open Source Security Tool Turbo Talks • Nmap Scripting Engine • IPv6 • Zenmap GUI • Nmap Suite • Final Notes & Q&A

    Universal Import Fixer (UIF) v1.0 (FINAL) by Magic_h2001

    &lt;br&gt; How to use : ============= 1.fill &lt;Process ID&gt; with target Process ID 2.fill &lt;Code Start&gt; with start address of code that you want to fix it. if you fill it with ZERO, UIF ...

    CAPLQuickstart_Generic_2018_Final.pdf

    Agenda Important information before getting started Visual Sequencer (GUI based programming (Subset of CAPL...Notes on Panel creation and use Where to find additional information Contact Information

    程序员考试刷题-software-dev-notes-final:软件开发笔记最终版

    程序员考试刷题软件开发笔记第 1 部分 [目录] 模块 1:介绍 软件工程是我们用来设计、构建、维护程序的工具/过程 开发好的代码还有很多,没有一种正确的方法来开发软件 软件应该是人类可以理解的、易于维护和可重用...

    ZhuoZhuoCrayon#CS-Notes#60. n 个骰子的点数1

    j++) /* 使用 i 个骰子最小点数为 i */final double totalNum = Math.pow(6, n);/* 旋转标记 *//* 旋转

    cs30-final-project

    GitHub上的Python文件: 用户指南参见user_guide.md和developing_notes.md 代码内容: 列表,元组,字典的使用磁贴根据其位置元组存储在字典中-(行,列) 参见grid_world.py ,第20、60和121行敌人存储在列表中...

    final-year-projects.notes:关于如何管理(第一年)“最后一年”项目并取得成功的说明

    期末项目 关于如何管理(第一年)“最后一年”项目并取得成功的说明。 在线浏览笔记@

    Beatles9527#StudyNotes#_1Java类更改常量后编译不生效1

    问题原因:在Java文件中,指向编译时static final的静态常量, 会被在运行时解析为一个局部的常量值(也就是说静态常量在编译后,成为了常量,而不是原先

    Universal Import Fixer (UIF) v1.2.rar

    2.fill &lt;Code Start&gt; with start address of code that you want to fix it. if you fill it with ZERO, UIF will fill it automatically. 3.fill &lt;Code End&gt; with End address of code that you want to fix it. ...

    PuppetMaster0.9

    - Many bug fixes and stability improvements, see the Release Notes for the complete list. PuppetMaster 0.9 is fully compatible with Final IK 1.9 and Unity 2017/2018/2019 versions. What can I do ...

Global site tag (gtag.js) - Google Analytics