Migration Play! Framework 1.2.3. Application Controller 2.0.

Out of curiosity, I would like to transfer the game! 1.2.3 Java application to play! 2.0, but I hardly understand the new application controller. I looked at three sample applications, but they did not help me much, since I am not an experienced programmer. Here is a stripped down example of how I am now approaching the application controller on Play! 1.2.3.

Classes Master and Details:

@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 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 this is far from elegant, but it works, and the code is easy for me to follow. I would like to do something similar using the new structure, and any help would be greatly appreciated.

+6
source share
1 answer

You can use wiki as a link. The new controller will look like:

 public class Application extends Controller { public static Result master(Long id) { Master master = Master.findById(id); return ok(master); } ... } 
+2
source

Source: https://habr.com/ru/post/904398/


All Articles