하나의 컨트롤러 (RegisteredController.java)가 있고 컨트롤러의 출력이 JSP (commment_form.jsp)에 표시되도록하고 싶습니다. . 그래서 jsp에서 forEach 태그를 사용하여 주석 목록 (사용자가 주어진 자원에 대해 삽입 한 주석)을 표시합니다. "자원"이란 보통 이미지를 의미합니다. 따라서 "이미지"에 대한 의견 목록이 있으며 주석이 주석 형식에 삽입 될 때 맨 아래 페이지에 모든 주석이 모두 표시되기를 원합니다. 내 질문에 JSP로 출력을 설정하려면 컨트롤러에 코드를 작성해야합니다 어떻게? @ModelAttribute, put 특성 또는 다른 것을 사용해야합니까?JSP의 foreach 태그와 Java 컨트롤러에서 코드를 작성하는 방법
comment_form.jsp은 다음과 같습니다 :
<form:form modelAttribute="comments">
<table class="commento">
<tr>
<th/>
<th>ID</th>
<th>Contenuto</th>
</tr>
<c:forEach items = "${comments}" var="comment">
<tr>
<td><c:out value="${comments.content}"></c:out></td>
<td><c:out value="${comments.content}</c:out></td>
</c:forEach>
</table>
</form:form>
RegisteredController.java은 다음과 같습니다
@RequestMapping("/comment.do")
public String comment(@ModelAttribute Comment comment, BindingResult
bindingResult, Model model, Locale locale) {
User user=userService.getUserCurrent();
comment.setDatePubblication(SQLUtility.getCurrentDate());
comment.setIdUser(user.getId());
commentService.create(comment);
Object[] args = { comment.getId() };
String message = messageSource.getMessage("message.update", args,locale);
List<Comment> comments =
commentService.findAllCommentByResource(comment.getIdResource());
model.addAttribute("comments", comments);
model.addAttribute("id",comment.getIdResource());
model.addAttribute("message", message);
model.addAttribute("comment", comment);
return "redirect:/registered/comment_start.do";
}
하시기 바랍니다 도움이 여기 컨트롤러와 JSP의 코드는? 나는 감사 할 것입니다 . 감사합니다.
* (나는이에 당신을 위해 그것을 해결 한 과도한 대문자 사용하지 마십시오 또한 * 태그는 제목에 포함되지 않습니다. 제목에서 "spring mvc"태그를 제거하고 태그에 추가했습니다. –