错误:类型Login不是Object controller的成员.Application(Play FrameWork)

时间:2017-04-02 01:54:37

标签: java playframework

我在使用IntelliJ的Play FrameWork上练习ZenTask (JavaGuided)。我完全遵循了概述的步骤,但我不断收到这个恼人的错误:

Error:(24, 196) type Login is not a member of object controllers.Application
class login extends BaseScalaTemplate[play.twirl.api.HtmlFormat.Appendable,Format[play.twirl.api.HtmlFormat.Appendable]](play.twirl.api.HtmlFormat) with play.twirl.api.Template1[Form[Application.Login],play.twirl.api.HtmlFormat.Appendable] {
Error:(27, 43) type Login is not a member of object controllers.Application
  def apply/*1.2*/(form: Form[Application.Login]):play.twirl.api.HtmlFormat.Appendable = {
Error:(71, 36) type Login is not a member of object controllers.Application
  def render(form:Form[Application.Login]): play.twirl.api.HtmlFormat.Appendable = apply(form)
Error:(73, 28) type Login is not a member of object controllers.Application
  def f:((Form[Application.Login]) => play.twirl.api.HtmlFormat.Appendable) = (form) => apply(form)

请帮助识别错误。我觉得这个框架非常错误和令人沮丧。

完成错误消息:

package models;

import com.avaje.ebean.Model;

import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class User extends Model {

    @Id
    public String email;
    public String name;
    public String password;

    public User(String email, String name, String password) {
        this.email = email;
        this.name = name;
        this.password = password;
    }

   public  Finder<String,User> find = new Finder<String,User>(
            String.class, User.class
    );

    public  User authenticate(String email, String password) {
        return find.where().eq("email", email)
                .eq("password", password).findUnique();
    }
}

这是我的代码:

form

控制器:loginFormrender(form(Login.class)))render(loginForm))package controllers; import models.User; import play.data.Form; import play.mvc.Controller; import play.mvc.Result; import views.html.index; import views.html.login; public class Application extends Controller { public Result index() { return ok(index.render("hello")); } public Result login() { return ok(login.render(form(Login.class))); } public Result authenticate() { Form<User> loginForm = Form.form(User.class).bindFromRequest(); if (loginForm.hasErrors()) { return badRequest(login.render(loginForm)); } else { session().clear(); session("email", loginForm.get().email); return redirect( routes.Application.index() ); } } public class Login { public String email; public String password; public User user; public String validate() { user.authenticate(email, password); if (user == null) { return "Invalid user or password"; } return null; } } } 中突出显示为错误:

@(form: Form[Application.Login])
<html>
    <head>
        <title>Zentasks</title>
        <link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")">
        <link rel="stylesheet" type="text/css" media="screen" href="@routes.Assets.at("stylesheets/login.css")">
    </head>
    <body>
        <header>
            <a href="@routes.Application.index" id="logo"><span>Zen</span>tasks</a>
        </header>

        @helper.form(routes.Application.authenticate) {
            <h1>Sign in</h1>
            @if(form.hasGlobalErrors) {
                <p class="error">
                @form.globalError.message
                </p>
            }

            <p>
                <input type="email" name="email" placeholder="Email" value="@form("email").value">
            </p>
            <p>
                <input type="password" name="password" placeholder="Password">
            </p>
            <p>
                <button type="submit">Login</button>
            </p>
        }

    </body>
</html>

观看次数:登录突出显示为错误。

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

# Home page
GET     /                           controllers.Application.index()
GET     /login                      controllers.Application.login()
POST    /login                      controllers.Application.authenticate()

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

路线:

<!DOCTYPE html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
  </head>
  <body>

  <div class ='container'>
    <h1>Get in touch!</h1>

    <div id='error'></div>

      <form>
        <div class="form-group">
          <label for="exampleInputEmail1">Email address</label>
          <input type="email" class="form-control" id="email" aria-describedby="emailHelp" placeholder="Enter email">
        </div>


        <div class="form-group">
          <label for="exampleInputPassword1">Subject</label>
          <input type="password" class="form-control" id="subject" placeholder="Subject">
        </div>


        <div class="form-group">
          <label for="exampleTextarea">Message</label>
          <textarea class="form-control" id="message" rows="3"></textarea>
        </div>
        <button type="submit" class="btn btn-primary" id="submit">Submit</button>
      </form>

    </div>

    <!-- jQuery first, then Tether, then Bootstrap JS. -->
    <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>

    <script type='text/javascript'>
    $('form').submit(function (e) {

      e.preventDefault();
      var error ="";

      if ($('#subject').val() == "") {
        error += 'The subject field is required.<br>';
      }

      if ($('#message').val() == "") {
        error += 'The message field is required.<br>';
      }


      if ($('#email').val() == "") {
        error += 'The email field is required.';
      }

      if (error != "" ) {
        $("#error").html(
        '<div class="alert alert-danger" role="alert"></p> <strong>Error(s) in your form:</strong></p>' + error +  '</div>');
      }else{
        $("form").unbind('submit').submit();
      }

    });
    </script>
  </body>
</html>

0 个答案:

没有答案