簡體   English   中英

游戲框架路由

[英]Playframework Routing

好的,所以我正在學習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;
    }
}

然后告訴我創建這些路線

# 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)

經過復核以確保書中的內容均正確無誤后,它給了我這個錯誤。

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

我知道這是播放框架的一種遺留方法,因為現在有了依賴項注入,但是即使閱讀了播放框架文檔,我也無法弄清楚如何使用它。 這是我的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