我正在尝试在网站上添加评论功能,但它没有出现在 foreach 循环中。
@RequestMapping("list.do")
public ModelAndView list(@RequestParam int bId, ModelAndView mav){
List<ReplyDto> listReply = replyService.listReply(bId);
mav.setViewName("board/replyList");
mav.addObject("list", listReply);
return mav;
}
replyList.jsp
<c:forEach var="row" items="${list}">
<tr>
${row.memId}
${row.rText}
</tr>
</c:forEach>
回复如下:
public class ReplyDto {
private Integer rId; // reply num
private Integer bId; // board num
private String rText; // reply text
private String memId;
public Integer getrId() {
return rId;
}
public void setrId(Integer rId) {
this.rId = rId;
}
public Integer getbId() {
return bId;
}
public void setbId(Integer bId) {
this.bId = bId;
}
public String getrText() {
return rText;
}
public void setrText(String rText) {
this.rText = rText;
}
...
}
最佳答案
memId
和 rText
是私有(private)的,因此无法访问,请改用公共(public) Getters:
<tr>
${row.getmemId()}
${row.getrText()}
</tr>
也关注Java/Oracle conventions for Methods :
Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized.
因此请考虑更改方法名称,例如从 getrText
到 getRText
关于java - 列表值未显示在 c :foreach loop 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46387977/