迁移玩!框架1.2.3应用控制器到2.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 wiki 作为参考。新的控制器将类似于:
You can use the wiki as a reference. The new Controller would be similar to: