简体   繁体   中英

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

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

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,然后从方法中删除静态声明。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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