1.很简单的,不用再添加什么其余的对象,直接就是在原来的对象里添加需要的数据就好了,一定要添加set和get方法。但是后台不需要在进行配置就行了。
2.代码
package com.marvin.book.pojo;
import java.util.HashSet;
import java.util.Set;
/**
* Booktype entity. @author MyEclipse Persistence Tools
*/
public class Booktype implements java.io.Serializable {
private static final long serialVersionUID = -4161453077878631323L;
private int id;
private String text;
private String description;
private boolean leaf;
private Booktype booktype;
private boolean expandable;
private int parent = (this.booktype!=null)?this.booktype.getId():0;
private Set books = new HashSet(0);
private Set children = new HashSet(0);
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean isLeaf() {
return leaf;
}
public void setLeaf(boolean leaf) {
this.leaf = leaf;
}
public Booktype getBooktype() {
return booktype;
}
public void setBooktype(Booktype booktype) {
this.booktype = booktype;
//精华就在这里哟 关系说明 将一个关联的对象转化为一个列传到前台,千万注意是在这个列所依靠的属性的set方法里面进行赋值啊
this.parent = (this.booktype!=null)?this.booktype.getId():0;
}
public boolean isExpandable() {
return expandable;
}
public void setExpandable(boolean expandable) {
this.expandable = expandable;
}
public int getParent() {
return parent;
}
public void setParent(int parent) {
this.parent = (this.booktype!=null)?this.booktype.getId():0;
}
public Set getBooks() {
return books;
}
public void setBooks(Set books) {
this.books = books;
}
public Set getChildren() {
return children;
}
public void setChildren(Set children) {
this.children = children;
}
public Booktype(int id, String text, String description, boolean leaf,
Booktype booktype, boolean expandable, int parent, Set books,
Set children) {
super();
this.id = id;
this.text = text;
this.description = description;
this.leaf = leaf;
this.booktype = booktype;
this.expandable = expandable;
this.parent = parent;
this.books = books;
this.children = children;
this.parent = (this.booktype!=null)?this.booktype.getId():parent;
}
public Booktype() {
super();
// TODO Auto-generated constructor stub
}
}
意思就是说,添加的数据一定要从他的父亲进行添加,要是有父亲,就一定有孩子。