2014-10-19 88 views
1

我自學自己玩框架,並從曼寧購買「玩for Java」。我按照他們的指示,自從這本書出版以來,已經有了一些更新(自然而然)。我收到以下錯誤:Play框架行動未找到:

行動沒有發現對於請求「GET /產品的

包控制器;

import play.mvc.Controller; 
import play.mvc.Result; 

public class Products extends Controller { 

    public static Result list(){ 
    return TODO; 
    } 

    public static Result newProduct(){ 
    return TODO; 
    } 

    public static Result details(String ean){ 
    return TODO; 
    } 

    public static Result save(){ 
    return TODO; 
    } 

} 

GET/controllers.Application.index()

GET /資產/ *文件controllers.Assets.at(路徑= 「/公共」,文件)

GET /產品/控制器.Products.list()

GET /產品/新controllers.Products.newProduct()

GET /產品/:EAN controllers.Products.details(EAN:字符串)

POST /產品/ controllers.Products.save()

我用HTML標籤對於這一點,我希望這是張貼在這裏的正確途徑。

回答

0

上次我使用Play Framework時,需要分別處理帶有斜槓的路徑,因爲此框架的路由引擎具有這種功能。

讓你無論是結尾的斜線添加到您的網址,或者你改變你的routes文件以下行:

GET /products/ controllers.Products.list() 

到:

GET /products controllers.Products.list() 

解決方法

我使用以下代碼從URL中刪除尾部斜槓:

如果我沒有記錯包含 path變量不帶後綴斜線的路徑

public class Reroute extends Controller { 
    public static Result trailingSlash(String path) { 
     /** 
     * Moved_Permantly is an HTTP code that indicates a moved ressource. The browser will 
     * cache the new address and redirect automatically if the user enters the old URL again. 
     */ 
     return movedPermanently("/" + path); 
    } 
} 

添加此行到你的routes文件:

# Reroute URL with a trailing slash 
GET /*path/ controllers.Reroute.trailingSlash(path: String) 

這是對應的類。如果您使用此代碼,請檢查是否指定了每條路線而沒有斜線,否則該路線將不再起作用。