Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upload List object into Model in Spring?

So, I've got the following method in the Controller:

@RequestMapping(value="/modules.htm",method = RequestMethod.GET )
protected String modules(ModelMap model) throws Exception {

      List<Module> modules = moduleService.getStudentModules(course_id);
      model.addAttribute....?
      return "modules";
}

And I need to display this list in jsp View, like:

<h1>Modules: </h1>
module 1 
module 2... etc

What do I need to add to show the full list on the JSP page? How should I upload it to the model and retrieve it? Thank you in advance.

like image 655
exomen Avatar asked Oct 17 '25 19:10

exomen


1 Answers

Pass the whole list:

model.addAttribute("modules", modules);

Then iterate on it:

<c:forEach items="${modules}" var="module">
    ${module.anyProperty}
</c:forEach>
like image 79
sp00m Avatar answered Oct 20 '25 10:10

sp00m