gpt4 book ai didi

java - 列表值未显示在 c :foreach loop 中

转载 作者:行者123 更新时间:2023-11-30 06:29:54 27 4
gpt4 key购买 nike

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

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

关于java - 列表值未显示在 c :foreach loop 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46387977/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com