java - Get specific value from Object in spring controller -
i have student class, studentdao
class, studentdetails
class , studentcontroller
student class have following instances:
private string studentid; private string studentname; private string studentgrade;
studentdao
gets these details db, studentdetails
class returns list of these details in following method:-
public list<student> getspecificstudentinfo(string studentid) { list<student> studentinfo=studentdao.getspecificstudentinfo(studentid); return studentinfo; }
in controller use hashmap student details like
public map<string, object> referencedata(httpservletrequest req)throws servletexception, ioexception { string studentid=req.getparameter("studentid"); map<string, object> studentrecord = new hashmap<string, object>(); studentrecord.put("students",studentdetails.getspecificstudentinfo(studentid)); return studentrecord; }
i m able display these values in jsp
using students.studentname
, students.studentgrade
, etc. 1 requirement.
but problem want use studentname
, studentgrade
further in controller in referencedata
method (before return statement ofcourse) m not getting right way.
i don't think did understand question. in referencedata, have studentid request. still extract grade using loop on list.
public map<string, object> referencedata(httpservletrequest req)throws servletexception, ioexception { string studentid=req.getparameter("studentid"); map<string, object> studentrecord = new hashmap<string, object>(); list<student> listofstudents = studentdetails.getspecificstudentinfo(studentid); string studentgrad = getgradefor(studentid); studentrecord.put("students",listofstudents); return studentrecord; } /* check nulls, empty list etc. */ public string getgradefor(list<student> listofstudent, string id) { (student student: listofstudent) { if (student.getid().equals(id)) return student.getgrade(); } return null; }
or build database query more , 1 object in list. student looking for.
Comments
Post a Comment