2012-04-30 17 views
1

我使用Akka和Play Mini(它只是Netty頂部的REST層)。我從Java使用它。語法很簡單,覆蓋在他們對GitHub的自述文件中:如何使用Play Mini的REST支持參數?

@URL("/coco/*/name/*") 

這工作正常,但意味着所有的URL必須只有長路徑。我發現this thread有一些人聲稱參數是過時的,其他人說他們絕對不是。我希望劇本剛剛說明他們的立場,但唉。我要尋找支持URL中的格式的能力:

/search/query=dogs 

也許經常玩文檔解決這個問題。將繼續搜索..

+0

這個怎麼樣pattern..http://stackoverflow.com/search Q = SW –

+0

呀,該格式與我的格式相同,但只是一個不同的參數名稱? – Rob

回答

2

也許這會幫助其他人。

@URL("/hello/*\\?*") 
public static Result show() { 
    Map<String, String[]> queryString = request().queryString(); 

    Map<String, String> data = new HashMap<String, String>(); 
    for (String key : queryString.keySet()) { 
     for (String value : queryString.get(key)) { 
      data.put(key, value); 
     } 
    } 
    response().setContentType("text/html"); 
    return ok(data.toString()); 
} 

如果用測試:curl "http://localhost:9000/hello/test?param1=0&param2=yes"

結果將是:

test{param1=0, param2=yes}