java - how to return two lists from controller class in spring mvc -
i have 2 tables call maintab,subtab generate menubar.
maintab has maitabid ,main_tab_name subtab has: sub_tb_id ,main_tb_id,subtab_name ,url
i want 2 list containig list1=maintabid & maintabname
list2=subtabname,maintabid & url
i want return 2 list using spring mvc. , retrieve in jsp page populate menu.please give me code of controller class , jsp: use hibernate , tile sample.
i tired
public string listmaintabandsubtabs(map<string, object> map) { map.put("maintab", new maintab()); map.put("maintablist", contactservice.listmaintab()); return "maintab"; }
how return subtabs , main tabs both 1 method....
why want return list, use map instead.
in controller can use,
map mp = new hashmap(); mp.put("list1", lst1); mp.put("list2", lst2); return mp;
in jsp, can iterate map,
for (map.entry<> entry : mp.entryset()) { string listkey = entry.getkey(); list<> childlst = entry.getvalue(); }
edit :
once have 2 list, can iterate them, in multiple ways,
you can use
for (x obj: childlst) { // x indicates class of object list contains system.out.println(obj); }
you can use iterator loop through list.
Comments
Post a Comment