We only need a table to achieve a tree-type directory structure of unlimited child nodes.
// 1. Sustained class
Public Class Catalog Implements Serializable {Private; Private String Name; Private Catalog Parent; Public Catalog () {Super ();
/ ** * @Return * / public set getchildren () {return children;}
/ ** * @Return * / public long getId () {return ID;}
/ ** * @Return * / public string getname () {return name;}
/ ** * @return * / public catalog getparent () {return parent;
/ ** * @Param set * / public void setchildren (set set) {children = set;}
/ ** * @Param l * / public void setid (long L) {id = L;
/ ** * @Param string * / public void setname (String string) {name = string;
/ ** * @Param catalog * / public void setparent (Catalog catalog) {public string toString () {Return New TostringBuilder (this) .append ("customerid", getId ()) .tostring (); }
Public Boolean Equals (Object Other) {if (! (@ (Other InstanceOf Catalog)) Return False; Catalog Castother = (Catalog) Other; Return New EqualsBuilder () .append (this.getid (), Castother.GetId ()) .isequals ();
Public Int hashcode () {return new hashcodebuilder () .append (getId ()) .tohashcode ();
/ ** * @Return * / public long getParentId () {return parentId;
/ ** * @Param long1 * / public void setparentId (long long1) {parentid = long1;}
}
// 2. Configuration
XML Version = "1.0"?>
Create Table `Catalog` (` ID` int (5) Not null auto_increment, `Name` VARCHAR (10) Not null,` parent_id` int (5) unsigned default '0' Not Null, Primary Key (`ID), Unique (`ID`), INDEX (` ID`);
// 4. Related test code