在 Spring Controller 中,我正在执行实体的两次迭代,如下所示:学生和类(class)需要传递到 View
//this is the first iterations
List<Students> searchList = studentService.getAllStudents(splitStr[0]);
for(Students listItems : searchList){
String firstname = listItems.getFirstname();
String lastname = listItems.getLastname();
}
//this is the second iterations
List<Course> courseList = courseService.getAllCourse(splitStr[0]);
for(Course listItems : searchList2){
...
}
目前我只能将其中一个列表传递给 View ,如下所示
return new ModelAndView("searchList", "searchList", searchList);
我的挑战是将这个列表也传递给 View ,但我只能返回一个 ModelAndView 对象
return new ModelAndView("searchList", "searchList", courseList);
最佳答案
如所示here ,你可以这样做:
ModelAndView mapCourseList = new ModelAndView("searchList");
mapCourseList.addObject("searchList", courseList);
return mapCourseList;
关于java - 将两个实体(学生、类(class))迭代的列表传递给 spring View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46361798/