我正在使用 Spring MVC 应用程序,并且我有一个带有以下代码的 JSP。
<c:choose>
<c:when test="${type eq 'school'}">
<h1 class="title">${schoolVO.name}</h1>
</c:when>
<c:when test="${type eq 'college'}">
<h1 class="title">${collegeVO.name}</h1>
</c:when>
<c:when test="${type eq 'tution'}">
<h1 class="title">${tutionVO.name}</h1>
</c:when>
...
..
..
Many other types...
</c:choose>
当控制器中有一个依赖于type
设置模型属性的方法时,将调用此 jsp。
如果类型是school
,它把
modelMap.addAttribute("schoolVO", school);
如果上大学
modelMap.addAttribute("collegeVO", college);
其他人也一样。。
现在我想删除这个<c:when>
条件jsp
。
现在取决于我想添加一个模型属性的类型并放置一个
schoolVO
或collgeVO
喜欢
modelMap.addAttribute("typeVO", "schoolVO");
这样我就不需要<c:when>
在jsp
. 我想使用类似的东西
${{typeVO}.name}
但这给了我错误
contains invalid expression(s): javax.el.ELException: Error Parsing:
我怎样才能做到这一点?提前致谢。
PS 我无法为我的问题找到正确的标题。如果我可以放一些合适的东西,请更改它。