how to display the information inside an object
we are assigned to implement the inside of a code block wherein it is associated with a given class (EmployeeProjectDetail) which is declared as a arraylist.
my code follows below.
public List<EmployeeProjectDetail> getEmployeeProjectHistory(long employeeID, long projectID) {
List<EmployeeProjectDetail> detailList = new ArrayList<EmployeeProjectDetail>();
return detailList;
}
I tried inputting the statements.
detailList.contains(projectDAO.getEmployeeProjects(employeeID));
detailList.contains(projectDAO.getEmployeeProjectRoles(employeeID, projectID));
the code then doesn't return any value but the invovled sql quer开发者_如何学编程ies in projectDAO class are thoroughly handled. any help will be appreciated.
contains checks whether an item is in a list what your are looking for is add.
You should add the line
detailList.add(projectDAO.getEmployeeProjects(employeeID));
Update (I'm guessing on the method and class names)
Based on the ClassCastException it appears that getEmployeeProjects(employeeID)
returns an ArrayList
. If the objects in this ArrayList
are EmployeeProjectDetail
's you can just replace the method body with return projectDAO.getEmployeeProjects(employeeID);
. If they are a different object representing a project, say EmployeeProject
, you would need to replace the method body with the following code:
List<Project> projects = projectDAO.getEmployeeProjects(employeeID);
ArrayList<EmployeeProjectDetail> projectDetails = new ArrayList<EmployeeProjectDetail>();
for (Project project : projects) {
if(project.getProjectID == projectID){
projectDetails.add(project.getProjectDetail());
}
}
精彩评论