java - How do I Iterate Tree data? -


i have data structure likeenter image description here

when query data base using

list<textualreq> textualreqlist = session.createquery("from textualreq parent null").list(); 

here textualreq object

  @id        @generatedvalue( generator = "increment" )        @genericgenerator( name = "increment", strategy = "increment" )        @column(name="id")        private int                    id;         @manytoone        @joincolumn(name="parent")        private textualreq                parent;        @onetomany( mappedby = "parent", cascade = cascadetype.all, fetch = fetchtype.eager )        @column(name="children")        private set<textualreq> children = new hashset<textualreq>();        @column(name="data")        private string                  data; 

i 2 records in "textualreqlist". needs iterate , show data enter image description here

i think should it!

public void displaydata(){     display(null); } public void display(textualreq textualreq){     list<textualreq> textualreqlist = null;      string parentid = "is null";      if(textualreq!=null){         parentid = "= "+textualreq.id;         system.out.println(textualreq.data);         system.out.print(" ");     }     textualreqlist = session.createquery("select * textualreq parent "+parentid).list();     if(textualreqlist==null)         return;     for(int i=0;i<textualreqlist.size();i++){         display(textualreqlist.get(i));     } } 

just call function displaydata().


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -