japid学习笔记

1. 控制输出时间
<div>
    <p>this part is cached for 10 seconds. Note the timeout spec with invoke overrides CacheFor annotation. </p>
    `a controllers.more.Portlets.panel2(b), "10s"
</div>
<p>内文字显示十秒钟然后进入panel2action

2.log:log directives are used to print a line of information to the console. It can take an argument of String
`log
`log a + i
`log "a message "
log命令用来在控制台输出一行信息,后面可以添加参数,输出结果如下:
japidviews/templates/log.html(line 5):
japidviews/templates/log.html(line 14): a10
japidviews/templates/log.html(line 18): a message

3.stopwatch m 输出render到模板所需的时间

4.~i  直接输出i的值

5.`each posts | String p 与`for String p : posts等价,
`for String p : posts
    <p>index: $_index, parity: $_parity, is odd? $_isOdd, is first? $_isFirst, is last? $_isLast, total size: $_size </p>
    call a tag:  `tag SampleTag p
`
输出index: 6, parity: even, is odd? false, is first? false, is last? true, total size: 6
另一种格式
`for (final Post p : posts) {
    another notation for invoking actions:  
    `invoke Application.echoPost(p)
`}

6.if-else循环语法:
    `if expr            `if(asBoolean(expr)){
        xxx                xxx    
    `else if expr        `} else if(asBoolean(expr)){
        yyy                yyy
    `else            `} else {
        zzz                zzz
    `            `

7.` suppressNull on如果下面出现了null的意外,如
` a = null;
safe to do a.something too: $a.length()
输出safe to do a.something too:

8.dontRedirect();控制不跳转页面,即停留在原页面。

说明:

∵在play运行时,调用一个action必须出发一个Http重定向

∴如果不想重定向,必须调用JapidController.dontRedirect()来避免

9.${a}, ~a, $a and ${escape(a)} and ~{a}这几种表达式的值相等

10.页面读取异常
    `for (Error e: errors()){
        <p>$e.getKey() : $e</p>
    `}

11.“Elvis操作符”是Java三目运算符的简写。一个便捷的用法是,如果表达式的值为false或者null,则返回一个合乎情理的默认值。好吧,我所实现的Elvis操作符确实不像Java中的一样:)我所添加的?:组合符号只在${}标签内起作用。
name ?: “empty”

12.`doBody m:带着参数回到原先界面。该命令中的参数列表必须与调用处的“|”之后的参数声明匹配,doBody通过匹配的参数传递到模板。

13.join(Strings, "|"):Strings是list,该方法为list中的每个元素见添加一个“|”,形成一个字符串。

14.`invoke与`a触发的action返回的结果直接插入到原先界面中,作为界面参数的一部分。注意:invoke出发的action不跳转页面。

15.renderJapid(Object... Objects):带着参数跳转到原先界面

16.renderJapidWith(String template, Object... args):带着参数跳转到指定模板,可以实现在一个action中渲染多种模板。

posted on 2012-01-14 15:40  timelyxyz  阅读(695)  评论(0编辑  收藏  举报

导航