formFactory.form()不存在!游戏框架 [英] formFactory.form() doesn't exist ! PlayFramework

查看:153
本文介绍了formFactory.form()不存在!游戏框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小问题,我想创建一个Web应用程序,并使用

I've a little problem, i want to create a web app and i learn PlayFramework with java documentation of

此示例代码:

public Result hello() {
    DynamicForm requestData = formFactory.form().bindFromRequest();
    String firstname = requestData.get("firstname");
    String lastname = requestData.get("lastname");
    return ok("Hello " + firstname + " " + lastname);
}

"formFactory"不存在.

The ''formFactory'' doesn't exist.

http://i.imgur.com/W941Bgz.png

为什么我没有此字段?

Why I don't have this field ?

当我要创建模型时,我没有模型类

And when i want to create a model, i don't have the model class

http://i.imgur.com/9FW7wp1.png

非常感谢您解决我的问题! :)

Thanks you so much if you resolve my problem ! :)

推荐答案

来自文档:

要包装类,您必须将play.data.FormFactory注入到Controller

To wrap a class you have to inject a play.data.FormFactory into your Controller

游戏已经了解FormFactory,因此只需为其添加一个构造函数参数即可:

Play already knows about FormFactory, so just add a constructor parameter for it:

public class FooController {

    private final FormFactory formFactory;

    @Inject
    public FooController(final FormFactory formFactory) {
        this.formFactory = formFactory;
    }

    public Result hello() {
        DynamicForm requestData = formFactory.form().bindFromRequest();
        String firstname = requestData.get("firstname");
        String lastname = requestData.get("lastname");
        return ok("Hello " + firstname + " " + lastname);
    }
}

我猜您提到的Model是EBean.您需要为您的项目启用EBean,然后在类路径上具有必需的类.

I'm guessing the Model you mention is that of EBean. You need to enable EBean for your project, and then you'll have the necessary classes on your classpath.

project/plugins.sbt中:

addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "3.0.0")

build.sbt:

lazy val myProject = (project in file(".")).enablePlugins(PlayJava, PlayEbean)

有关更多信息,请参见相关文档.

More information is available in the relevant docs.

这篇关于formFactory.form()不存在!游戏框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆