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中渲染多種模板。