×
JFinal 摘要

第0章 极速体验Model与Bean

0.1 极速体验 Generator0.2 JFinal相关生成文件0.3 Model 与 Bean 合体

第一章 快速上手

1.1 JFinal创建项目1.2 放入 JFinal 库文件1.3 修改 web.xml1.4 添加 java 文件1.5 JFinal启动项目1.6 开启浏览器看效果1.7 Maven 下开发

第二章 JFinalConfig

2.1 概述2.2 configConstant(Constants me)2.3 configRoute(Routes me)2.4 configPlugin (Plugins me)2.5 configInterceptor (Interceptors me)2.6 configHandler (Handlers me)2.7 afterJFinalStart()与 beforeJFinalStop()2.8 PropKit

第三章 Controller

3.1 概述3.2 Action3.3 getPara 系列方法3.4 getModel 与 getBean 系列方法3.5 setAttr 方法3.6 getFile 文件上传3.7 renderFile 文件下载3.8 session 操作方法3.9 render 系列方法

第四章 AOP

4.1 概述4.2 Interceptor4.3 Before4.4 Clear4.5 Interceptor 的触发4.6 Duang、Enhancer4.7 Inject 拦截器

第五章 ActiveRecord

5.1 概述5.2 ActiveRecordPlugin5.3 Model5.4 JavaBean 与 Model 合体5.5 JFinal 独创 Db + Record 模式5.6 声明式事务5.7 Cache5.8 Dialect 多数据库支持5.9 表关联操作5.10 复合主键5.11 Oracle 支持5.12 多数据源支持5.13 非 web 环境下使用 ActiveRecord

第六章 EhCachePlugin

6.1 概述6.2 EhCachePlugin6.3 CacheInterceptor6.4 EvictInterceptor6.5 CacheKit6.6 ehcache.xml 简介

第七章 RedisPlugin

7.1 概述7.2 RedisPlugin7.3 Redis 与 Cache7.4 非 web 环境使用 RedisPlugin第八章 Validator第九章 国际化第十章 FreeMarker 基础第十一章 JFinal 架构及扩展

3.9 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。


此外,还可以通过 constants.setMainRenderFactory(IMainRenderFactory)  来设置 Controller.render(String)所使用的视图,IMainRenderFactory 专门用来对 Controller.render(String) 方法扩展除了 FreeMarker、JSP、Velocity 之外的视图。

假设 在 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().forIE()) 或 者 render(new JsonRender(params).forIE())。这种情况只出现在 IE 浏览器 ajax 文件上传,其它普通 ajax 请求 不必理会。

2:除 renderError 方法以外,在调用 render 系列的方法后程序并不会立即返回,如果需要立即 返回需要使用 return 语句。在一个 action 中多次调用 render 方法只有最后一次有效。


分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)