天天看點

Jfinal controller 部分方法

部分方法:

1、擷取參數:getPara(String name);

getParaToInt(String name) ,将傳回參數的值轉為int;

getPara() ,url中參數連接配接為/v1-v2-v3,該方法請求傳回v1-v2-v3參數整體值;

getPara(0) ,url中參數連接配接方式為/v1-v2-v3,該方法請求傳回v1;

getParaToInt(1) ,将傳回參數的值轉為int,若url中參數連接配接方式為/2-3-N8,該方法請求傳回3,n或N代表負數

2、檔案上傳:getFile(String name,saveUrl,maxSize,encode);

3、資料傳遞:setAttr(string,Object),存儲的值在頁面中使用el表達式能擷取到;

4、傳回用戶端:render("test.html"),渲染名為 test.html 的視圖,該視圖的全路徑為”/path/test.html”;

 render(”/other_path/test.html”),渲染名為 test.html 的視圖,該視圖的全路徑 為”/other_path/test.html”,即當參數以”/”開頭時将采用絕對路徑;

 renderJsp(”test.html”),渲染名為 test.html 的視圖,且視圖類型為 Jsp。

 renderJson() 将所有通過 Controller.setAttr(String, Object)設定的變量轉換成 json 資料并渲染

renderJson(“users”, userList),以”users”為根,僅将 userList 中的資料轉換成 json資料并渲染。

renderJson(user)  将 user 對象轉換成 json 資料并渲染

注意:注意:

1:IE 不支援 contentType 為 application/json,在 ajax 上傳檔案完成後傳回 json 時 IE 提示下載下傳文

件,解決辦法是使用:render(new JsonRender(params).forIE())。

2:除 renderError 方法以外,在調用 render 系列的方法後程式并不會立即傳回,如果需要立即

傳回需要使用 return 語句。在一個 action 中多次調用 render 方法隻有最後一次有效。

5、擷取request:getRequest();

6、擷取response:getResponse();

繼續閱讀