Clouda URL使用說明
URL是Web app中很重要的部分,在router部分介紹過URL中pattern與controller的關(guān)系,在這節(jié)將詳細(xì)介紹Clouda中URL的格式和使用。
Clouda中URL的組成格式如下:
- 域名/{controller}/{arguments[1]}/{arguments[2]}/...?params1=string¶ms2=string
-
controller
與router中的pattern對應(yīng)
-
arguments
URL中的傳遞參數(shù)
-
params
與controller中使用env.redirect(queryPath ,paramMap)傳遞的paramMap對應(yīng)
一個URL格式的實(shí)例:
- URL: localhost:8080/debug.html/studentList/index/123/007?p=2
對應(yīng)router定義為:
- sumeru.router.add{
- {
- pattern: '/studentList/index',
- action: 'App.studentList'
- }
- }
上面介紹了Clouda中URL的組成規(guī)則,那么Clouda是如何解析URL呢?下面介紹Clouda的解析方法。
-
自動匹配到 /controller是/studentList/index
-
將后面的參數(shù) /123/007 作為 arguments傳入env.arguments
-
將p傳入session和controller的params參數(shù)中
在上面的實(shí)例中看到URL中帶有參數(shù),那么如何獲取URL中的參數(shù)呢?可按照下面方法獲?。?/p>
-
env.arguments["/studentList/index","123","007"]
-
session.get('p')或者通過上面Controller之間傳參部分中的params.p獲取;
一般在開發(fā)階段需要在瀏覽器中對應(yīng)用進(jìn)行debug,看到應(yīng)用的源碼;而在開發(fā)完成發(fā)布后,不希望別人看到應(yīng)用的源碼,為了滿足開發(fā)者的這種需求,Clouda有調(diào)試模式和正式模式。
-
調(diào)試模式
使用debug.html訪問進(jìn)入調(diào)試模式,在調(diào)試模式下可以看到工程的源碼,方便在瀏覽器中進(jìn)行調(diào)試
- localhost:8080/debug.html/studentList/index/123/007?p=2
-
正式模式
使用index.html訪問進(jìn)入正式模式,在正式模式下看到的是經(jīng)過編譯后代碼
- localhost:8080/index.html/studentList/index/123/007?p=2