The JSP page loops through the List collection through the c:forEach tag

 

 

 

The <c:forEach> tag has the following attributes:

Attributes description Is it necessary Defaults
items Information to be recycled no no
begin Starting element (0=first element, 1=second element) no 0
end The last element (0=first element, 1=second element) no Last element
step The step size of each iteration no 1
where The name of the variable representing the current entry no no
varStatus The name of the variable representing the loop state no no

In general, items and var can be used, and varStatus is used when you want to get the current object index

Backstage 

 
  1.  
  2. public ModelAndView toaddSmallBoard() {

  3. /*需要获取板块信息*/

  4. ModelAndView modelAndView=new ModelAndView();

  5. List boards=boardService.getBoards();

  6. modelAndView.addObject("boards",boards);

  7. modelAndView.setViewName("admin/addSmallBoard");

  8. return modelAndView;

  9. }

Front desk

I used the select drop-down box here, and the specific use situation shows the situation

 
  1. <select class="form-control" name="board.boFaterId">

  2. <c:forEach items="${boards}" var="board" varStatus="id">

  3. <option value="${board.boardId}">${board.boardName} </option>

  4. </c:forEach>

  5. </select>

effect

Guess you like

Origin blog.csdn.net/zy103118/article/details/109492592