Sto*_*ran 7 scala playframework playframework-2.2
我在play framework 2.2上开发应用程序我有一个像这样的路由文件:
GET /posting/ controllers.posting.BlogController.allPosts()
GET /posting/:number controllers.posting.BlogController.allPosts(number: Int)
Run Code Online (Sandbox Code Playgroud)
和BlogContriller:
object BlogController extends Controller {
def allPosts(pageNumber:Int = 1, postsPerPage:Int = 10) = Action{
val posts = Post.getLastNPosts(postsPerPage, postsPerPage*(pageNumber-1))
val htmlPosts = new Html(new StringBuilder());
for (post <- posts){
val htmlPost = views.html.posting.post(post.getName, post.getText, post.getDate.toString)
htmlPosts += htmlPost;
}
Ok(views.html.posting.index(htmlPosts))
}
}
Run Code Online (Sandbox Code Playgroud)
当我试图加入时,我给出了一个错误:
Error:(14, -1) Play 2 Compiler: C:\...\conf\routes:14: Compilation error[Using different overloaded methods is not allowed. If you are using a single method in combination with default parameters, make sure you declare them all explicitly.]
GET /posting/:number controllers.posting.BlogController.allPosts(number: Int)
Run Code Online (Sandbox Code Playgroud)
我无法理解如何解决这个问题.谁能帮我?
您必须使用带默认值的参数:
GET /posting/ controllers.posting.BlogController.allPosts(number: Int = 1)
GET /posting/:number controllers.posting.BlogController.allPosts(number: Int)
Run Code Online (Sandbox Code Playgroud)
您可能不会使用重载方法allPosts(Int)和allPosts.由于您allPosts使用默认值声明了两个参数,因此Scala将此方法视为4种不同的方法.您只能使用其中一个.
| 归档时间: |
|
| 查看次数: |
4650 次 |
| 最近记录: |