Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Playframework 未找到播放框架操作:_Playframework - Fatal编程技术网

Playframework 未找到播放框架操作:

Playframework 未找到播放框架操作:,playframework,Playframework,我正在自学Play框架,并从Manning购买了“Play for Java”。我遵循他们的指示,自从这本书出版以来,自然有了一些更新。我得到以下错误: 找不到请求“获取/产品”的操作 包装控制器 import play.mvc.Controller; import play.mvc.Result; public class Products extends Controller { public static Result list(){ return TODO; }

我正在自学Play框架,并从Manning购买了“Play for Java”。我遵循他们的指示,自从这本书出版以来,自然有了一些更新。我得到以下错误:

找不到请求“获取/产品”的操作

包装控制器

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/assets/*file controllers.assets.at(path=“/public”,file)

GET/products/controllers.products.list()

GET/products/newcontrollers.products.newProduct()

GET/products/:ean控制器.products.details(ean:String)

POST/products/controllers.products.save()


我在这里使用了HTML标记,我希望这是在这里发布的正确方式。

上次我使用Play框架时,有必要单独处理带有尾部斜杠的路径,因为该框架的路由引擎会这样做

因此,您可以在URL中添加尾随斜杠,也可以在
routes
文件中更改为以下行:

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

解决方法

我使用以下代码从URL中删除尾部斜杠:

将以下行添加到您的
routes
文件:

GET /products/ controllers.Products.list()
# Reroute URL with a trailing slash
GET    /*path/    controllers.Reroute.trailingSlash(path: String)
这是对应的类:

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);
    }
}
如果我没有记错,那么包含
path
变量的路径后面没有斜杠。如果使用此代码,请检查指定的每个路由是否没有尾部斜杠,否则该路由将不再工作