Java JSTL打印嵌套对象
如何在JSP页面的映射中打印嵌套对象/属性的值Java JSTL打印嵌套对象,java,jsp,map,jstl,Java,Jsp,Map,Jstl,如何在JSP页面的映射中打印嵌套对象/属性的值 <c:foreach items="${survey}" var="survey"> <c:out value="${survey.value}" /> </c:foreach> 假设Survey有一个名为Questions的属性(这是另一个对象),我想打印这些问题(Survey.Questions.getId()或Survey.Questions.getTitle()),foreach语句的外
<c:foreach items="${survey}" var="survey">
<c:out value="${survey.value}" />
</c:foreach>
假设Survey有一个名为Questions的属性(这是另一个对象),我想打印这些问题(Survey.Questions.getId()或Survey.Questions.getTitle()),foreach语句的外观如何
编辑:测量是地图而不是集合如果嵌套特性是单个对象实例,则直接引用它,如:
<c:forEach var="surveyItem" items="${surveys}">
${surveyItem.title} <!-- You can use the c:out if you really want to -->
</c:forEach>
这将打印每个问题
的标题,假设您有一个调查
对象绑定到调查
属性,并且调查
对象有一组问题
对象作为字段(使用适当的getter方法,即getQuestions()
)
也可以有嵌套循环,如:
<c:forEach var="surveyItem" items="${surveys}">
${surveyItem.title}
<c:forEach var="question" items="${surveyItem.questions}">
${question.title}
</c:forEach>
</c:forEach>
如果嵌套属性是单个对象实例,则直接引用它,如:
<c:forEach var="surveyItem" items="${surveys}">
${surveyItem.title} <!-- You can use the c:out if you really want to -->
</c:forEach>
这将打印每个问题
的标题,假设您有一个调查
对象绑定到调查
属性,并且调查
对象有一组问题
对象作为字段(使用适当的getter方法,即getQuestions()
)
也可以有嵌套循环,如:
<c:forEach var="surveyItem" items="${surveys}">
${surveyItem.title}
<c:forEach var="question" items="${surveyItem.questions}">
${question.title}
</c:forEach>
</c:forEach>
基本上,如果您的调查是另一个集合对象,您需要在循环中迭代两次。比如说,
<c:foreach items="${survey}" var="survey">
<c:out value="${survey.value}" />
<c:foreach items="${survey.Question" var="question">
$<c:question.item> or $<c:question.title>
</c:foreach>
</c:foreach>
美元或$
基本上,如果您进行调查,您需要在循环中迭代两次。问题是另一个集合对象。比如说,
<c:foreach items="${survey}" var="survey">
<c:out value="${survey.value}" />
<c:foreach items="${survey.Question" var="question">
$<c:question.item> or $<c:question.title>
</c:foreach>
</c:foreach>
美元或$
请重新表述您的问题。“调查”是一个列表吗,地图?请重新表述你的问题。“调查”是一个列表吗,地图?如果调查是一个地图,这会发生什么变化?如果调查是一个地图,这会发生什么变化?