c:foreach 循环中不显示列表值

list values dosen't show up in c:foreach loop

我正在尝试在网站上添加评论功能,但它没有出现在 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;
    }
    ...
}

memIdrText 是私有的,因此无法访问,请改用 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.

因此考虑更改方法名称,例如从 getrTextgetRText