2015-06-21 71 views
0

我正在构建我的第一个控制器的Play框架。我收到的错误:播放框架路由错误,我不能修复

Compilation error value getAll is not a member of controllers.api.protocol.Period 

我routes.conf文件看起来像:

# Routes 
# This file defines all application routes (Higher priority routes first) 
# ~~~~ 

# Home page 
GET  /         controllers.Application.index() 

GET  /api/protocol/period     controllers.api.protocol.Period.getAll() 

# Map static resources from the /public folder to the /assets URL path 
GET  /assets/*file  controllers.Assets.versioned(path="/public", file: Asset) 

和 “控制器/ API /协议/ Period.java” 的模样:

package controllers.api.protocol; 

import com.avaje.ebean.Model; 
import play.mvc.Controller; 
import java.util.List; 
import play.mvc.*; 
import static play.libs.Json.toJson; 

public class Period extends Controller { 

    public static Result getAll() { 
     List<model.Protocol.Period> periods = new Model.Finder<Integer.class>(model.Protocol.Period.class).all(); 
     return ok(toJson(periods)); 
    } 
} 

我迷路了。

回答

1

这很好,也很受欢迎。 :)

删除staticpublic static Result getAll(),你是排序。

+0

我有同样的问题,但为什么你必须删除静态时,我发现在所有的例子是这样吗? 最新版本有什么变化? – pagurix

+1

@pagurix:比较https://www.playframework.com/documentation/2.3.x/JavaActions和https://www.playframework.com/documentation/2.4.x/JavaActions正如你所看到的,在Play 2.4中你是不再需要为控制器的方法使用静态。相关:Play 2.4介绍DI – Anton

+0

是的,@Anton说什么,你看到的例子大概是2.3,而不是2.4,因为2.4还是比较新的。 – bjfletcher