java - Spring :Display List<ObjectID> in jsp view

标签 java jsp spring-mvc

我是 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/

相关文章:

java - java中向数组添加变量元素

java - JSP中pageContext.REQUEST_SCOPE和request对象的区别

jquery - Where 子句无法正常工作 : No converter found for return value of type: class java. util.ArrayList

spring-mvc - Hybris 中的自定义 500 错误页面

java - Spring MVC 尝试从 GET 请求方法中的重定向获取参数

Java 输入流缓冲区对象?

java - 如何使用 Spring Security ACL 获取用户有权访问的域对象列表?

java - 无法从环境变量中读取值

jsp - JaCoCo-将JSP排除在报告之外

java - Spring MVC SseEmitter - 连接异常中止