简体   繁体   English

游戏框架路由

[英]Playframework Routing

Ok So I am learning play framework and I understand the routes concept but the Play for Java Book is telling me to create a Products controller class like this one below 好的,所以我正在学习play框架并且了解路由概念,但是Play for Java Book告诉我在下面创建一个Products控制器类。

package controllers;

import com.google.inject.Inject;
import play.mvc.Controller;
import play.mvc.Result;

public class Products extends Controller {

    public static Result list() {
        return TODO;
    }

    public static Result showBlank(){
        return TODO;
    }

    public static Result show(Long ean) {
        return TODO;
    }

    public static Result save(){
        return TODO;
    }
}

And then it tells me to create these routes 然后告诉我创建这些路线

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

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

GET /products/ controllers.Products.list()
GET /products/new controllers.Products.showBlank()
GET /products/:ean controllers.Products.show(ean: Long)
POST /products/ controllers.Products.save()





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

After reviewing to make sure everything was correct in the book it gives me this error. 经过复核以确保书中的内容均正确无误后,它给了我这个错误。

value list is not a member of controllers.Products
In C:\Users\Rijos\PlayJavaBook\conf\routes:8
5# Home page
6GET     /                           controllers.Application.index()
7
8GET /products/ controllers.Products.list()
9GET /products/new controllers.Products.showBlank()
10GET /products/:ean controllers.Products.show(ean: Long)
11POST /products/ controllers.Products.save()
12

I know that this is a legacy way of doing this is the play framework because of the dependency injection now, but even after reading the play framework documentation I cant figure out how to use it. 我知道这是播放框架的一种遗留方法,因为现在有了依赖项注入,但是即使阅读了播放框架文档,我也无法弄清楚如何使用它。 Here is my build.sbt file 这是我的build.sbt文件

name := """play-java"""

version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayJava)

scalaVersion := "2.11.6"

libraryDependencies ++= Seq(
  javaJdbc,
  cache,
  javaWs
)

// Play provides two styles of routers, one expects its actions to be injected, the
// other, legacy style, accesses its actions statically.
routesGenerator := InjectedRoutesGenerator


fork in run := true

尝试在控制器上添加@Singlton,然后从方法中删除静态声明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM