LoginSignup
2
2

More than 5 years have passed since last update.

PlayFramework1.0系でURLの最後を/{id}.{format}にする方法

Last updated at Posted at 2013-11-24

URLの動的部分のマッチングは、/[^./]+/が使われるそうなので、

routesを↓のように設定すると

上手くいかないroutes
GET  /path/{id}.{format}    Controller.method

http://example.com/12345.json
というリクエストをしても、コントローラー側では、
{id} に"12345.json"
{format}に null
が設定されてしまい。意図した動きにならない。
そこでマッチングの正規表現を/[^.]+/に変えてマッチングさせる。

設定

正しいroutes
GET  /path/{<[^\.]+>id}.{format}    Controller.method

コントローラー側は、

static public void method(String id, String format){
    // some logic
}

と設定すると、id, formatにURLから値が設定される。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2