gpt4 book ai didi

java - jSTL:无法解析表达式 [${item.class.name == 'List' }]

转载 作者:行者123 更新时间:2023-12-01 22:50:08 26 4
gpt4 key购买 nike

下面的 jSTL 代码应该基于此 Controller 方法解析 json 文件:

Controller

@RequestMapping(value="listagem.json", method=RequestMethod.GET)
@PreAuthorize("hasPermission(#user, 'listagem_'+#this.this.name)")
public ModelAndView listagem_json(@RequestParam("pagina") String pagina, @RequestParam("items") String items, @RequestParam("ordem") String ordem) {
ModelAndView mav = new ModelAndView();

mav.setViewName("listagem");
mav.addObject("lista", serv.listagem(pagina, items, ordem));
mav.addObject("map", serv.getListaAtributos());

return mav;
}

jSTL代码

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="json" uri="http://www.atg.com/taglibs/json" %>
<json:object>
<json:array name="item" var="item" items="${lista}">
<json:object>
<c:forEach var="attr" items="${map}">
<c:choose>
<c:when test="${empty attr.value}">
<json:property name="${attr.key}" value="${item[attr.key]}"/>
</c:when>
<c:otherwise>
<c:choose>
<c:when test="${item.class.name == 'List'}">
<json:array name="${attr.key}" var="attr2" items="${item[attr.key]}">
<json:object>
<c:forEach var="attr3" items="${attr.value}">
<json:property name="${attr3}" value="${attr2[attr3]}"/>
</c:forEach>
</json:object>
</json:array>
</c:when>
<c:otherwise>
<json:array name="${attr.key}">
<json:object>
<c:forEach var="attr2" items="${attr.value}">
<c:set value="${attr.key}" var="object"/>
<json:property name="${attr2}" value="${object}.${attr2}"/>
</c:forEach>
</json:object>
</json:array>
</c:otherwise>
</c:choose>
</c:otherwise>
</c:choose>
</c:forEach>
</json:object>
</json:array>
</json:object>

但是当我运行应用程序并请求 json 文件时,会发生此错误:

org.apache.jasper.JasperException: /WEB-INF/json/listagem.jsp (line: 13, column: 9) "${item.class.name == 'List'}" contains invalid expression(s): javax.el.ELException: Failed to parse the expression [${item.class.name == 'List'}]

任何人都可以告诉我如何编写此表达式 ${item.class.name == 'List'} 来实现预期结果的正确方法?

最佳答案

您可以使用以下两者之一:

${item.getClass().simpleName == "List"} 
${item['class'].simpleName == "List"}

有关更多详细信息,请参阅此 post

关于java - jSTL:无法解析表达式 [${item.class.name == 'List' }],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24846134/

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