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域对象模型

这一层是商业软件的核心。该模型在一个应用程序的中心地位。负责代表的业务概念,有关业务情况的信息和业务规则。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值