gpt4 book ai didi

java - 使用 JSTL 从 map 获取值

转载 作者:行者123 更新时间:2023-11-30 04:05:43 26 4
gpt4 key购买 nike

我尝试在这里查看不同的问题,但没有一个完全匹配。

I get Map data from the source as <Key,Value> pairs, typically a JSON source

我尝试过这样的事情

<tr>
<c:forEach items="${record.attributes.entry}" var="entry">
<td style="width: 20%; height: 15px;">
<img
src="${entry['p_csl_thumbnail_url']}"
class="img-responsive" />
</td>
<td style="width: 65%; height: 15px;" class="ellipses">
${entry['p_csl_description']}

</td>
<td style="width: 15%; height: 15px;" class="ellipses">
${entry['p_csl_close_time_est']}
</td>
</c:forEach>
</tr>

其中条目是一个 map ,我正在尝试使用键获取值。

示例数据:

{
"records": [
{
"aggregationCount": "0",
"attributes": {
"entry": [
{
"key": "P_CSL_Description",
"value": " [i]test[/i] Description"
},
{
"key": "P_RSCG_Lot_Creation_Time",
"value": "0"
},
{
"key": "P_CSL_Close_Time_EST",
"value": "2013-09-16 06:25:00 PM EST"
},
{
"key": "P_CSL_Thumbnail_Url",
"value": "http://localhost:9889/54205775_lists.jpg"
}
]
},
"recordId": "LCOM6693760",
"selfLocation": {
"uri": "http://localhost:8899/search-engine/v1/collections/csl/search?recordId=LCOM6693760"
}
}
]
}

更新

<tr>
<td style="width: 10%; height: 15px;">
<img src="${record.attributes.entry['P_CSL_Thumbnail_Url']}" class="img-responsive" />
</td>
<td style="width: 80%; height: 15px;">
${record.attributes.entry['P_CSL_Description']}
</td>
<td style="width: 10%; height: 15px;">
${record.attributes.entry['P_CSL_Close_Time_EST']}
</td>
</tr>

我遇到以下错误

 SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.NumberFormatException: For input string:
"P_CSL_Thumbnail_Url" at
java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:492) at
java.lang.Integer.parseInt(Integer.java:527) at
javax.el.ListELResolver.coerce(ListELResolver.java:173) at
javax.el.ListELResolver.getValue(ListELResolver.java:52) at
org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:104)
at org.apache.el.parser.AstValue.getValue(AstValue.java:183) at
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
at
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:1026)
at
org.apache.jsp.view.jsp.search_jsp._jspx_meth_c_005fforEach_005f4(search_jsp.java:1225)

最佳答案

带有类似的声明

<c:forEach items="${record.attributes.entry}" var="entry">

entryMap.Entry 类型的对象。因此,您可以简单地执行

    <td style="width: 20%; height: 15px;">
<img
src="${entry.key}"
class="img-responsive" />
</td>

获取键,${entry.value}获取值。

关于java - 使用 JSTL 从 map 获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20778968/

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