In many cases, we need to use a double loop to display the content.
For example, if you need to display partitions cyclically and the sections in the partition, the previous practice is
Obtain the partition set based on the partition ID on the page.
.
This destroys the organization of the business logic layer, presentation layer, and data access layer.
Solution:
Instantiate a list generic set, put it in Map <string, Object>, and put it in list in map.
Code:
/********************** Set the Forum list ************* * *************/<br/> List <Map <string, object> forumlists = new arraylist <Map <string, Object> (); <br/> List groupforumlists = forumsdao. getgroupforumslist (); <br/> for (INT I = 0; I <groupforumlists. size (); I ++) {<br/> Map <string, Object> forummap = new hashmap <string, Object> (); <br/> forums Forum = (forums) groupforumlists. get (I); <br/> // partition name <br/> forummap. put ("groupname ", Forum. getname (); <br/> // partition id <br/> forummap. put ("groupid", Forum. getfid (); <br/> // obtain the section set in the partition ID. <br/> List flists = forumsdao. getforumslist (Forum. getfid (); <br/> List <Map <string, string> FL = new arraylist <Map <string, string> (); <br/> for (Int J = 0; j <flists. size (); j ++) {<br/> forums fm = (forums) flists. get (j); <br/> Map <string, string> Fo = new hashmap <string, string> (); <br/> Fo. put ("forumname", FM. getname (); <Br/> Fo. put ("threadsnum", FM. getthreads () + ""); <br/> Fo. put ("postsnum", FM. getposts () + ""); <br/> Fo. put ("lastpost", FM. getlastpost (); <br/> Fo. put ("FID", FM. getfid () + ""); <br/> // fo. put ("todayposts", FM. gettodayposts () + ""); <br/> int todaypostnumbyfid = postsdao. gettodaypostnumbyfid (FM. getfid (); <br/> Fo. put ("todayposts", todaypostnumbyfid + ""); <br/> moderators moderator = moderatorsdao. findmoderatorsbyfid (FM. getfid (); <br/> If (Moderator! = NULL) {<br/> members member = membersdao. findmemberbyid (moderator. getuid (); <br/> If (member! = NULL) {<br/> Fo. put ("membername", member. getUserName (); <br/> Fo. put ("memberid", member. getuid () + ""); <br/>}< br/> List threads = threadsdao. getlistthreadsbyfid (FM. getfid (); <br/> If (threads. size ()! = 0) {<br/> threads newthread = (threads) threads. get (0); <br/> Fo. put ("TID", newthread. gettid () + ""); <br/> Fo. put ("subject", newthread. getsubject (); <br/> Fo. put ("threadauthor", newthread. getauthor (); <br/> Fo. put ("threaddateline", newthread. getdateline (). tostring (); <br/>}< br/> FL. add (FO); <br/>}< br/> // Add to the section set <br/> forummap. put ("Forums", FL); <br/> // put it into the total set <br/> forumlists. add (forummap); <br/>}< br/> request. setattribute ("forumlists", forumlists );