好的,我正在学习play框架,我理解路由概念,但是Play for Java Book告诉我创建一个产品控制器类,如下所示
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我知道,这是一种遗留的方法,因为现在是依赖注入,所以这就是play框架,但是即使在阅读了play框架文档之后,我也不知道如何使用它。这是我的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发布于 2016-01-10 20:50:21
尝试在控制器上添加@Singlton,并从方法中删除静态声明。
https://stackoverflow.com/questions/34710288
复制相似问题