0
的JSTL代碼下面應在此控制器的方法分析JSON文件基礎:
控制器
@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文件要求,這個錯誤HAP筆:
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.class.simpleName == 「列表」} –