gpt4 book ai didi

java - 将带有列表的 hibernate POJO 隐藏为可序列化的 rpc 返回对象

转载 作者:太空宇宙 更新时间:2023-11-04 10:39:54 25 4
gpt4 key购买 nike

hibernate POJO只允许list(一个接口(interface))来映射多对一关系。

public class Employee {
private int id;
private String firstName;
private String lastName;
private int salary;
private List certificates;

但是GWT-RPC只允许具体类型作为返回,例如ArrayList。因此,不要只为 RPC 定义一个与 ArrayList 类似的类,

public class EmployeeRPC {
private int id;
private String firstName;
private String lastName;
private int salary;
private **ArrayList<Certificate>** certificates;

还有其他方法可以将hibernate POJO转换为可序列化对象吗?

谢谢

最佳答案

您可以使用 List<Serializable> 但生成的 javascript 会更大。

When passing objects across RPC call's its a good practice to declare concrete parameter types in the RPC interface. If for some reason you cannot use concrete class in the RPC interface try to be as specific as possible.
This is because the GWT compiler while emitting javascript has to take into account all possible variants of List in the compilation unit. This includes all the classes extending List and Serializable interface in the class path. The permutations can be huge, which will effect your compile time as well as the application download size.

Full answer here

使类可序列化以用于 GWT RPC:

A class is serializable if it meets these three requirements:
- It implements either Java Serializable or GWT IsSerializable interface, either directly, or because it derives from a superclass that does.
- Its non-final, non-transient instance fields are themselves serializable, and
- It has a default (zero argument) constructor with any access modifier (e.g. private Foo(){} will work)

Docu

你必须将这些东西添加到你的类中......还要确保 Certificate 是可序列化的。

或者只使用 JSON:resty-gwt , gwt-jackson

关于java - 将带有列表的 hibernate POJO 隐藏为可序列化的 rpc 返回对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49107254/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com