简体   繁体   中英

How to combine ArrayList of different objects into one list / Map and then retrive value of each arraylist from combined list /Map?

I have a function that have 3 arraylists of bean classes.I want to add/combine them into one and return that through function.That combined arraylist is received by controller. I want to retrive all arraylists seperately and put set a variable that will be used to show data on jsp page.

I have this code inside function where I am getting values from database.I want to combine sbean1,tbean1 and dbean1 and return it through function.

public /* datatype*/ selectMyBlogs(){

/* code for getting data from database*/

List<StudentBean> sbeanl = null;
List<TeacherBean> tbeanl = null;
List<DepartmentBean> dbeanl = null;

StudentBean sbean = new StudentBean(sid,sname,scourse,sdept);
sbeanl = new ArrayList<StudentBean>();
sbeanl.add(sbean);
TeacherBean tbean = new TeacherBean(tid,tename,tsubject,tsal,tdept);
tbeanl = new ArrayList<TeacherBean>();
tbeanl.add(ebean);
DepartmentBean dbean = new DepartmentBean(did,dcourses,dstudents,dteachers);
dbeanl = new ArrayList<DepartmentBean>();
dbeanl .add(dbean);

/* code to combine all lists*/

return /* combined data */;
}

This is my controller class function where I will get the value return from above function.dbconn is the object of class and selectMyData() is the function in which above code resides.Then want to fetch each list data seperately and give them a variable using request.setAttribute() method so that I can show data on my jsp page. I am doing this so because I want to show data of student teacher and dept on one page.

private void viewMyData(HttpServletRequest request , HttpServletResponse response) throws ServletException, IOException{
        
/*what will come here - list/Map? */ = dbconn.selectMyData();

/* how to fetch seperate list data here*/

request.setAttribute("", );

/*then use set setAttribute method so that data can be show on jsp page*/

RequestDispatcher rd = request.getRequestDispatcher("myData.jsp");
rd.forward(request, response);
}

Please somebody tell how can I do that. I tried it to combine using arraylist but I don't know what will be come in angular brackets of that list.

I have a function that have 3 arraylists of bean classes.I want to add/combine them into one and return that through function.That combined arraylist is received by controller. I want to retrive all arraylists seperately and put set a variable that will be used to show data on jsp page.

I have this code inside function where I am getting values from database.I want to combine sbean1,tbean1 and dbean1 and return it through function.

public /* datatype*/ selectMyBlogs(){

/* code for getting data from database*/

List<StudentBean> sbeanl = null;
List<TeacherBean> tbeanl = null;
List<DepartmentBean> dbeanl = null;

StudentBean sbean = new StudentBean(sid,sname,scourse,sdept);
sbeanl = new ArrayList<StudentBean>();
sbeanl.add(sbean);
TeacherBean tbean = new TeacherBean(tid,tename,tsubject,tsal,tdept);
tbeanl = new ArrayList<TeacherBean>();
tbeanl.add(ebean);
DepartmentBean dbean = new DepartmentBean(did,dcourses,dstudents,dteachers);
dbeanl = new ArrayList<DepartmentBean>();
dbeanl .add(dbean);

/* code to combine all lists*/

return /* combined data */;
}

This is my controller class function where I will get the value return from above function.dbconn is the object of class and selectMyData() is the function in which above code resides.Then want to fetch each list data seperately and give them a variable using request.setAttribute() method so that I can show data on my jsp page. I am doing this so because I want to show data of student teacher and dept on one page.

private void viewMyData(HttpServletRequest request , HttpServletResponse response) throws ServletException, IOException{
        
/*what will come here - list/Map? */ = dbconn.selectMyData();

/* how to fetch seperate list data here*/

request.setAttribute("", );

/*then use set setAttribute method so that data can be show on jsp page*/

RequestDispatcher rd = request.getRequestDispatcher("myData.jsp");
rd.forward(request, response);
}

Please somebody tell how can I do that. I tried it to combine using arraylist but I don't know what will be come in angular brackets of that list.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM