A method that implements a Dual Loop instead of accessing the data access layer on pages.

Source: Internet
Author: User

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 );

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.