play2中的路由:如何匹配网址的一部分

Fre*_*ind 2 routes playframework-2.0

有一些网址如:

http://localhost:9000/images/111111.jpg
http://localhost:9000/images/222222.png
http://localhost:9000/images/333333.gif
Run Code Online (Sandbox Code Playgroud)

它们将映射到一个方法:

def showImage(id: String) = Action {
    val image = Image.findById(id).get
    Ok.sendFile(new File(image.path)
}
Run Code Online (Sandbox Code Playgroud)

请注意,id是文件名的唯一部分显示,网址:111111,222222,333333

所以我在路线中写了一个映射:

GET  /images/$id<\w+>.*          controllers.Images.showImage(id)
Run Code Online (Sandbox Code Playgroud)

在部分中$id<\w+>.*,id匹配id,并.*匹配将被忽略的后缀.

但语法不正确,错误信息是:

Identifier expected
Run Code Online (Sandbox Code Playgroud)

怎么解决?

Jul*_*Foy 5

目前无法通过Play 2实现这一点.作为一种解决方法,您可以在控制器操作中处理您的参数:

GET    /images/:id       controllers.Images.showImage(id)
def showImage(idWithExt: String) = Action {
  val id = idWithExt.takeWhile(_ != '.')
  ...
}