播放表单和带参数错误的GET请求

时间:2013-06-01 04:42:53

标签: scala playframework routes playframework-2.0

在Play框架中,路由会出现编译错误

这里

错误

GET  /allFriends    controllers.Application.listAllFriends(userId:Long?=)

模板

 @(myFriends: List[MyFriend])
    @import helper._
    @import helper.twitterBootstrap._


    @for(myFriend <- myFriends){
        @myFriend.friend_Id <br>
    }

错误

string matching regex `[^),?=\n]' expected but `)' found 

1 个答案:

答案 0 :(得分:3)

路线文件中存在语法错误:如果您使用?=,则userId中的controllers.Application.listAllFriends(userId:Long?= <here>)需要默认值。

如果查看Play Routing documentation,您会看到:

GET  /allFriends    controllers.Application.listAllFriends(userId:Long)

将匹配/allFriends?userId=1但不匹配/allFriends

GET  /allFriends    controllers.Application.listAllFriends(userId:Long ?= -1)

还会将/allFriends与默认值-1匹配。