我是 Spring 的新手。我的域名是
@Document
public class Post {
@Id
private ObjectId _id;
private String postTitle;
private String postDesc;
private ObjectId owner=Global.getCurruser();
private List<ObjectId> intrestReceived=new ArrayList<ObjectId>();
// Getters and setters
}
我的 Controller 看起来像
@RequestMapping(value = "/post/intrestReceived", method = RequestMethod.GET)
public String intrestReceived(Model model){
List<Post> result=postService.intrestReceived();
model.addAttribute("result", result);
return "intrestReceived";
}
我的观点如下:
<form:form id="idForm" class="form-horizontal" method="GET">
<table border=1>
<tr>
<td><b>Post ID</b></td>
<td><b>Post Desc</b></td>
<td><b>Intrest Received</b></td>
</tr>
<c:forEach items="${result}" var="result">
<tr>
<td>${result.getId()}</td>
<td>${result.postDesc}</td>
<td>${result.getIntrestReceived()}</td>
</tr>
</c:forEach>
</table>
</form:form>
这里<td>${result.getIntrestReceived()}</td>
返回 List<ObjectId>
我如何迭代它以在单独的行中获取单独的 id 。
对不起我的英语。
最佳答案
试试这个:
<c:forEach items="${result}" var="item">
<tr>
<td>${item._id}</td>
<td>${item.postDesc}</td>
<c:forEach items="${result.intrestReceived}" var="intr">
<tr><td>${intr._id}</td></tr>
</c:forEach>
</tr>
</c:forEach>
关于java - Spring :Display List<ObjectID> in jsp view,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19945866/