Spring boot 使用JSTL标记连接两个变量以检查空条件

Spring boot 使用JSTL标记连接两个变量以检查空条件,spring-boot,jstl,Spring Boot,Jstl,我试图在ModelMap中分别发送每个用户的图像 model.addAttribute("profileImage"+i, sb); // I have added attribute in loop 变量“i”是我为每个用户迭代的每个图像的索引 现在我有了profileImage0、profileImage1、profileImage2等等 在访问时,我设置了一些条件 <c:choose> <c:when test="${profileImage!=null}"&g

我试图在ModelMap中分别发送每个用户的图像

model.addAttribute("profileImage"+i, sb); // I have added attribute in loop
变量“i”是我为每个用户迭代的每个图像的索引

现在我有了profileImage0、profileImage1、profileImage2等等

在访问时,我设置了一些条件

<c:choose>
    <c:when test="${profileImage!=null}">
    <center><img src="${profileImage}"  id="${profileImage}" class="rounded-circle img-circle img-responsive" style="height:90px;width:90px;" alt="Avatar">
    </c:when> 
    <c:otherwise>
    <center><img src="${pageContext.request.contextPath}/resources/images/defaultuserprofile.png"  id="${profileImage}" class="rounded-circle img-circle img-responsive" style="height:90px;width:90px;" alt="Avatar"></center>
    </c:otherwise>
</c:choose> 
因此,在上面的代码中,我需要将一些索引附加到一个变量,它将首先初始化一个变量的值,然后正确地使用它,而不是像这样使用它

与profileImage0、profileImage1等类似……

您可以使用标记来迭代变量。您可能希望传入控制器中的最大值数,以便知道需要从请求中获取多少值:

<c:forEach var = "i" begin = "1" end = "${max}">
  <c:set var = "variableName" scope = "session" value = "profileName + ${i}"/>
  <c:set var = "profileImage" scope = "session" value = "${variableName}"/>
</c:forEach>
或者类似的事情