Java Play:bindFromRequest()不起作用

Ash*_*esh 1 html java forms scala http-post playframework

我正在尝试Java Play,我遇到了直接的障碍.情况非常简单,设置简单.

我有一个名为的模型类Person非常简单,看起来像这样;

package models.models;

import play.db.ebean.Model;

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

/**
 * Created by asheshambasta on 25/07/14.
 */
@Entity
public class Person extends Model {

    @Id
    public Integer id;

    public String name;
}
Run Code Online (Sandbox Code Playgroud)

我的路线定义为;

POST    /person                     controllers.Application.addPerson()
Run Code Online (Sandbox Code Playgroud)

接下来,我在addPerson里面有一个动作controllers.Application,就是这样

public static Result addPerson() {
    Person person = form(Person.class).bindFromRequest().get();
    person.save();
    Logger.debug(person.toString());
    Logger.debug(form().get("name"));
    return redirect(controllers.routes.Application.index());
}
Run Code Online (Sandbox Code Playgroud)

index.scala.html看起来像:

@(message: String)

@main("Welcome to Play") {
        <form action="@routes.Application.addPerson()" method="post">
            <input type="text" name="name" />
            <button>Add person</button>
        </form>
}
Run Code Online (Sandbox Code Playgroud)

我还检查了我的浏览器调试工具,我看到name表单元素正确地发布到服务器.

发生的事情很奇怪:在动作中似乎没有任何表单参数可见.正如您所看到的,我有两个Logger.debug,每个都显示对象中的name属性为null person,以及尝试使用时检索form.get("name").

我已经尝试过我能看到的最好的方法来解决这个问题,但我在网上看不到这个问题.这似乎太基础了,不能成为Play框架的问题.

我在这做错了什么?

作为一个注释,我在Mac上,我正在使用mySQL来存储数据.

Raj*_*ena 6

在尝试使用Java时,我也遇到了同样的问题.

原因:当您将Eclipse项目首选项设置为时,似乎会出现问题Build automatically.这会混淆播放所产生的类,并将其改为eclipse在更改时生成的类.

解决方案: Disable the 'build automatically'从项目设置和终端,做一个play clean从Play创建类!

让我知道如果这有效,很多人都面临同样的问题.这应该是文档本身参考中的一个提示.