PLAY框架开发中文手册

PLAY框架开发中文手册2010-03-19 11:16PLAY开发中文手册

PLAY开发实战中文手册

PLAY功能中文手册

PLAY中文API手册

有需要的请MSN联系:hmguo@hotmail.com

Controllers

执行模板:

public class Clients extends Controller {

public static void index() {

render();

}

}

路径:app/views/Clients/index.html
app/views/Controller/(action names) .html

数据添加到模板范围:

using the renderArgs object。使用renderArgs对象。

public class Clients extends Controller {

public static void show(Long id) {

Client client = Client.findById(id);

renderArgs.put("client", client);

render();

}

}

模板使用:<h1>Client ${client.name}</h1>

更简单的办法:

直接用render(...)方法。

public static void show(Long id) {

Client client = Client.findById(id);

render(client);

}

进一步:

public static void show(Long id) {

Client client = Client.findById(id);

render(id, client);

}

指定另一个模板:

不希望使用默认模板,使用自己指定的模板。

public static void show(Long id) {

Client client = Client.findById(id);

render("Clients/showClient.html", id, client);

}

重定向到另一个URL:

使用redirect(...)。

public static void index() {

redirect("http://www.zenexity.fr");

}

不支持:Forward。(因为没有servlet)注:

一个HTTP请求只能调用一个动作,如果你需要调用另一个动作,重定向浏览器URL,调用另一个动作。


拦截:

@Before @After @Finally

These methods have to be static but not public.

添加更多拦截器,使用@With。

测试@Test

An HTTP request:

1.The URI path: in /clients/1541, 1541 is dynamic part of the URI Pattern.

2.The Query String: /clients?id=1541.

3.The request body: if the request was sent from an HTML form, the request body contains the form data encoded as x-www-urlform-encoded.


package controllers;


import models.Client;

import play.mvc.Controller;


public class Clients extends Controller {


public static void show(Long id) {

Client client = Client.findById(id);

render(client);

}


public static void delete(Long id) {

Client client = Client.findById(id);

client.delete();

}


}


Each public, static method in a Controller is called an action. The signature for an action method is always :

public static void action_name(params...);

render(...)是一个执行结果的方法,并显示一个模板。

import play.mvc.Controller;

params

public static void show() {

String id = params.get("id");

String[] names = params.getAll("names");

}

public static void show() {

Long id = params.get("id", Long.class);

}

public static void show(Long[] id) {

for(String anId : id) {

System.out.println(id);

}

}

public static void show(List<Long> id) {

for(String anId : id) {

System.out.println(id);

}

}


Models域对象模型

这一层是商业软件的核心。该模型在一个应用程序的中心地位。负责代表的业务概念,有关业务情况的信息和业务规则。
MVC应用程序模型 - 7 - app/controllers - 8 - app/models - 8 - app/views - 8 - 请求生命周期 - 8 - 标准应用程序布局layout - 9 - app目录 - 9 - public目录 - 10 - conf目录 - 10 - lib目录 - 11 - 开发生命周期 - 11 - 连接到java调试器 - 12 - 类增强Enhancement - 13 - 02.HTTP路由 - 13 - 关于REST - 14 - routes文件语法 - 14 - HTTP方法 - 15 - URI范示 Pattern - 15 - Java调用定义 - 17 - 把404当作action来用 - 17 - 指派静态参数 - 17 - 变量和脚本 - 18 - 路由优先级 - 18 - 服务器静态资源 - 18 - staticDir: mapping - 18 - staticFile: mapping - 19 - URL 编码 - 19 - 反转路由:用于生成某些URL - 19 - 设置内容风格(CSS) - 20 - HTTP 内容协商 negotiation - 21 - 从http headers开始设置内容类型 - 21 - 定制格式 - 22 - 03.控制器 - 23 - 控制器概览 - 23 - 获取http参数 - 24 - 使用params map - 25 - 还可以从action方法签名实现转换 - 25 - 高级HTTP Java绑定 - 26 - 简单类型 - 26 - Date类型 - 26 - Calendar日历 - 27 - File - 27 - 支持类型的数组或集合 - 28 - POJO对象绑定 - 29 - JPA 对象绑定 - 30 - 定制绑定 - 30 - @play.data.binding.As - 30 - @play.data.binding.NoBinding - 31 - play.data.binding.TypeBinder - 31 - @play.data.binding.Global - 32 - 结果类型 - 32 - 返回一些文本类型的内容 - 33 - 返回一个JSON字符串 - 33 - 返回一个XML字符串F - 34 - 返回二进制内容 - 34 - 作为附件下载文件 - 34 - 执行一个模板 - 35 - 跳转到其他URL - 36 - Action链 - 36 - 定制web编码 - 37 - 拦截器 - 38 - @Before - 38 - @After - 39 - @Catch - 40 - @Finally - 41 - 控制器继承 - 42 - 使用@With注释添加更多的拦截器 - 42 - Because Java does not allow multiple inheritance, it can be very limiting to rely on the Controller hierarchy to apply interceptors. But you can define some interceptors in a totally different class, and link them with any controller using the @With annotation.由于java不允许多继承,通过控制器继承特点来应用拦截器就受到极大的限制。但是我们可以在一个完全不同的类里定义一些拦截器,然后在任何控制器里使用@With注释来链接他们。 - 42 - Session和Flash作用域 - 42 - 04.模板引擎 - 43 - 模板语法 - 43 - Expressions: ${…} - 44 - Template decorators : #{extends /} and #{doLayout /} - 44 - Tags: #{tagName /} - 45 - Actions: @{…} or @@{…} - 46 - Messages: &{…} - 46 - Comment: *{…}* - 46 - Scripts: %{…}% - 46 - Template inheritance继承 - 47 - 定制模板标签 - 48 - 检索tag参数 - 48 - 调用标签体 - 48 - 格式化特定标签 - 49 - 定制java标签 - 49 - 标签命名空间 - 50 - 在模板里的Java对象扩展 - 51 - 创建定制扩展 - 52 - 模板里可以使用的保留对象 - 52 - 05.用play验证http数据
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值