迁移玩!框架1.2.3应用控制器到2.0

发布于 2024-12-22 11:07:11 字数 1157 浏览 0 评论 0原文

出于好奇,我想迁移一个 Play! 1.2.3 Java 应用程序来玩吧! 2.0,但我很难理解新的应用程序控制器。我已经检查了三个示例应用程序,但它们对我帮助不大,因为我不是经验丰富的程序员。这是我目前如何在 Play 中处理应用程序控制器的一个精简示例! 1.2.3.

Master 和 Detail 类:

@Entity
public class Master extends Model {
    public String name;
    public String address;
    @OneToMany(cascade=CascadeType.ALL,mappedBy="detailId")
    public List<Detail> details;
}

@Entity
public class Detail extends Model {
    public String pet;
    @JoinColumn(name="detail_id")
    @ManyToOne
    public Master detailId;
}

Application 类:

public class Application extends Controller {

    public static void master(Long id) {
        Master master = Master.findById(id);
        render(master);
    }

    public static void saveMaster(final Master master) {
        master.save();
    }

    public static void saveDetail(Long id, final Detail detail) {
        Master master = Master.findById(id);
        detail.detailId = master;
        detail.save();
        master.details.add(detail);
        master.save();
        master(id)
   }
}

我知道它远非优雅,但它可以工作,并且代码对我来说很容易理解。我想使用新框架做类似的事情,任何帮助将不胜感激。

Out of curiosity I would like to migrate a Play! 1.2.3 Java application to Play! 2.0, but I'm having difficulty understanding the new application controller. I've examined the three example applications, but they've been of little help to me as I'm not an experienced programmer. Here is a stripped down example of how I currently approach an application controller in Play! 1.2.3.

The Master and Detail classes:

@Entity
public class Master extends Model {
    public String name;
    public String address;
    @OneToMany(cascade=CascadeType.ALL,mappedBy="detailId")
    public List<Detail> details;
}

@Entity
public class Detail extends Model {
    public String pet;
    @JoinColumn(name="detail_id")
    @ManyToOne
    public Master detailId;
}

The Application class:

public class Application extends Controller {

    public static void master(Long id) {
        Master master = Master.findById(id);
        render(master);
    }

    public static void saveMaster(final Master master) {
        master.save();
    }

    public static void saveDetail(Long id, final Detail detail) {
        Master master = Master.findById(id);
        detail.detailId = master;
        detail.save();
        master.details.add(detail);
        master.save();
        master(id)
   }
}

I know it's far from elegant but it works and code is easy for me to follow. I would like to do something similar using the new framework and any help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

堇色安年 2024-12-29 11:07:11

您可以使用 wiki 作为参考。新的控制器将类似于:

public class Application extends Controller {

    public static Result master(Long id) {
        Master master = Master.findById(id);
        return ok(master);
    }

    ...
}

You can use the wiki as a reference. The new Controller would be similar to:

public class Application extends Controller {

    public static Result master(Long id) {
        Master master = Master.findById(id);
        return ok(master);
    }

    ...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文