java代码:
TreeNode root = new TreeNode();
root = Json.fromJsonFile(TreeNode.class, new File("E:/workspace/start/WebContent/Resources/js/tree-data.json"));
for(TreeNode node:root.getChildren()){
System.out.println(node.getChildren().size());
}
dao.insertWith(root, "children");
json代码
{
text: 'root',
id: 'root',
children: [{
text:'业务流程',
id:'yw',
children:[{
text:'进',
id:'in',
leaf:true
},{
text:'销',
id:'out',
leaf:true
}]
},{
text:'报表中心',
id:'reports',
children:[{
text:'报表1',
id:'report1',
leaf:true
},{
text:'报表2',
id:'report2',
leaf:true
}]
},{
text:'基础设置',
id:'basicSetting',
expanded: true,
children:[{
text:'用户',
id:'user',
leaf:true
},{
text:'客户',
id:'customer',
leaf:true
},{
text:'供应商',
id:'supplier',
leaf:true
}]
}]
}
类映射如下:
public class TreeNode {
@Id
private long tid;
private long pid;
@Name
private String id;
private String text;
private boolean leaf;
@Many(target=TreeNode.class, field="pid")
private List<TreeNode> children;
只插入了第一级和第二级,第三级或第n级如何插入呢?