使用flex和java,当实体具有关系(一对多或任何其他)时如何填充数据网格
我在前端使用flex4,在后端使用java spring服务。 当我按照教程进行操作时,我可以从数据库(mysql5.0)获取实体并填充Flex在客户端提供的数据网格。但是,问题是当我的实体包含与另一个实体(我的意思是对象)的关系时,我什至无法编写该对象的任何字符串属性。
为了清楚起见,让我举一个前任;
@Entity
@Table(name = "roleInfo")
public class RoleInfo implements Serializable {
/**
*
*/
private static final long serialVersionUID = -8297592329833181352L;
@Column(name = "username")
private String username;
@OneToMany(fetch = FetchType.EAGER, cascade = { CascadeType.ALL }, mappedBy = "roleInfo")
private List<Role> roles;
@Entity
public class Role ... {
private String name;
//accesor methods.. vs. vs..
..
}
现在,我很高兴听到您的解决方案,以便在列出 roleInfo 实体的数据时打印出 Role 对象的名称。
此外,这里是柔性侧 ex;
<mx:columns>
<mx:DataGridColumn headerText="username" dataField="username"/>
<mx:DataGridColumn headerText="name" dataField="roles.name"/> //Prob. is here, It didnt work:)
..
</mx:columns>
I am using flex4 on the frontend, and java spring services on the backend.
When I follow the tutorials, I can get entities from db (mysql5.0) and fill the datagrid provided by Flex on the client side. However, what the trouble is when my entity include a relation with another entity (I mean an Object) I cannot write even any string property of that object.
To clearify let me give an ex;
@Entity
@Table(name = "roleInfo")
public class RoleInfo implements Serializable {
/**
*
*/
private static final long serialVersionUID = -8297592329833181352L;
@Column(name = "username")
private String username;
@OneToMany(fetch = FetchType.EAGER, cascade = { CascadeType.ALL }, mappedBy = "roleInfo")
private List<Role> roles;
@Entity
public class Role ... {
private String name;
//accesor methods.. vs. vs..
..
}
Now, I would be glad to hear your solutions in order to print out the name of the Role object while I am listing datas of roleInfo entity.
Moreover, here the flex side ex;
<mx:columns>
<mx:DataGridColumn headerText="username" dataField="username"/>
<mx:DataGridColumn headerText="name" dataField="roles.name"/> //Prob. is here, It didnt work:)
..
</mx:columns>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 labelFunction 属性来实现此目的。在那里,您可以迭代角色列表并生成连接字符串并返回该字符串。
You can use the labelFunction property of the DataGridColumn to achieve this. In there you can iterate over the roles list and generate a concatenated string and return the string.