我正在运行最新的 Play Framework 2.5.1,但我的登录页面出现错误:
错误:
value login is not a member of controllers.Application
我尝试添加 @
符号,即:
@controllers.Application.login()
并从 build.sbt
中删除注入(inject)器,清理/清理文件并在“CMD”中更新。我正在使用 https://www.playframework.com/documentation/2.1.0/JavaGuide 中的示例.
HTML代码
@(form: Form[Application.Login])
<html>
<head>
<title>Zentasks</title>
<link rel="shortcut icon" type="image/png" href="@routes.Assets.versioned("images/favicon.png")">
<link rel="stylesheet" type="text/css" media="screen" href="@routes.Assets.versioned("stylesheets/login.css")">
</head>
<body>
<header>
<a href=@routes.Application.index" id="logo"><span>Zen</span>tasks</a>
</header>
</body>
</html>
Controller
package controllers;
import play.*;
import play.mvc.*;
import views.html.*;
public class Application extends Controller {
public Result index() {
return ok(index.render("Your new application is ready."));
}
public static Result login() {
return ok(
login.render(form(Login.class))
);
}
public static class Login {
public String email;
public String password;
}
}
路线
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~
# Home page
GET / controllers.Application.index()
GET /login controllers.Application.login()
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file @controllers.Assets.versioned(path="/public", file: Asset)
最佳答案
从 Controller 的操作中删除 static
关键字。 Play 2.5.1 默认使用依赖注入(inject),如果你想使用static
Action ,你需要 explicitly configure it .因此,您的登录操作必须是这样的:
// no static keyword here
public Result login() {
return ok(login.render(form(Login.class)));
}
更新:
顺便说一句,你在这里混合了很多东西。我建议您在为 2.5.x 版开发时不要遵循 2.1.0 指南,因为这两个版本之间存在很多差异。事实上,Play 2.1.0 是从 2013 年 2 月 6 日开始的。
以下是一些解释您的代码失败原因的引用资料:
关于java - Play Framework - 值登录不是 controllers.Application 的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36345421/