Datasheet simple java class - many mapping

For example: Given a classification and sub-classification

Get the following information:

1. A complete classification of information;

The classification sub-categories corresponding acquired

package Mapping_transformation;

class item
{
    private long id ;
    private  String title ;
    private subitem subitems[] ;          //一个分类有多个子分类
    public item(long id , String title)
    {
        this.id = id ;
        this.title = title ;
    }

    public void setSubitems(subitem[] subitems) {
        this.subitems = subitems;
    }

    public subitem[] getSubitems() {
        return subitems;
    }

    public String getInfo()
    {
        return "【分类信息】id = "+this.id + " title = "+this.title ;
    }

}
class subitem
{
    private long id ;
    private  String title ;
    private item item ;
    public subitem(long id , String title)
    {
        this.id = id ;
        this.title = title ;
    }
    public void setItem(item item)
    {
        this.item =Item; 
    } 
    public Item the getItem () 
    { 
        return Item; 
    } 
    public String getInfo () 
    { 
        return "sub category [] = ID" + the this .id + "title =" + the this .title; 
    } 
} 
public  class one_to_many {
     public  static  void main (String [] args) { 
        Item Item = new new Item (001, "programming books" ); 
        SubItem SubItems [] = new new SubItem [] {
                 new new SubItem (002, "Java from entry to abandon" ),
                 new newsubitem (003, "c ++ from entry to abandon" ) 
        }; 
        item.setSubitems (SubItems);              // a plurality of sub-classification of classification 

        for ( int I = 0; I <subitems.length; I ++ ) 
        { 
            SubItems [I]. the setItem (Item); 
        } 


        System.out.println (item.getInfo ()); 
        for ( int   I = 0;. I <item.getSubitems () length; I ++ ) 
        { 
            System.out.println (item.getSubitems () [I] .getInfo ()); 
        } 
    } 
}
resul: 
[classified information] id = 1 title = programming books [sub] classified information the above mentioned id = 2 title = the Java from entry to abandon [sub] classified information the above mentioned id = 3 title = c ++ from entry to give up

 

Guess you like

Origin www.cnblogs.com/fairy-land/p/11965167.html