2014-07-16 9 views
2
<c:forEach var="healthp" items="${healthparam}" > 
    <tr> 
<td><c:out value="${healthp.name}"/></td> 
<td><c:out value="${healthp.current_Reading}"/></td> 
<td><c:out value="${healthp.target}"/></td> 
<td><c:out value="${healthp.measurementunit}"/></td> 
<td><c:out value="${healthp.target}"/></td> 
<td><c:out value="${healthp.recorddate}"/></td> 
    </tr> 
</c:forEach> 

이 항목에서 Current_Reading을 대상과 비교하려고합니다. 현재 읽기가 더 높은 값이면 그 (Current_Reading) 열에 표시하고 싶습니다. 그렇지 않으면 대상 열에 표시하고 싶습니다. 도움이 필요합니다.JSTl의 forEach 태그를 통해 액세스하는 동안 값을 비교하는 방법

답변

3

c : if 태그를 사용할 수 있습니다. 내가 제대로 이해하고 (낮은 쪽) current_Reading 또는 대상 중 하나의 값을 숨기려면, 다음은 다음과 같이 수 :

<td><c:out value="${healthp.name}"/></td> 
    <td> 
    <c:if test="${healthp.current_Reading > healthp.target}"> 
     <c:out value="${healthp.current_Reading}"/> 
    </c:if> 
    </td> 
    <td><c:out value="${healthp.target}"/></td> 
    <td><c:out value="${healthp.measurementunit}"/></td> 
    <td> 
    <c:if test="${healthp.current_Reading <= healthp.target}"> 
     <c:out value="${healthp.target}"/> 
    </c:if> 
    </td> 
    <td><c:out value="${healthp.recorddate}"/></td> 

이것은 하나의 빈 열이 당신을 떠날 것, 즉 당신이 무엇인지 찾고있어.

+0

멋진 답변입니다. 그러나 OP가 두 조건 모두에서 Current_Reading을 표시하려고하는 것처럼 보입니다. 그러나 조건에 따라 OP는이 값을 다른 열에 표시하려고합니다. –

+0

감사하고 그것이 작동하는지 여부를 확인하자. –

+0

고마워 ..... 나를 위해 작동 –

1

표현 언어를 사용하는 동안 ne, lt 등뿐만 아니라 eq를 사용할 수 있습니다.

<c:if test="${var1 eq var2}">some code</c:if> 
0

나는이 기술이 당신이 찾고있는 것이라고 믿습니다. 은 "삼항"연산자는 하나의 열 두 값의 높은 표시하는 깨끗한 방법 :

<c:forEach var="healthp" items="${healthparam}" > 
<tr> 
    <td><c:out value="${healthp.name}"/></td> 
    <td><c:out value="${healthp.current_Reading > healthp.target ? healthp.current_Reading : healthp.target}"/></td> 
    <td><c:out value="${healthp.measurementunit}"/></td> 
    <td><c:out value="${healthp.target}"/></td> 
    <td><c:out value="${healthp.recorddate}"/></td> 
</tr> 
</c:forEach> 

사이드 노트 : 당신이 당신의 코드를 할 수 있도록, 더 이상 아웃 : 대부분의 현대 JSP 구현은 C를 필요로하지 않습니다 이렇게하면 더 읽을 수 있습니다.

<c:forEach var="healthp" items="${healthparam}"> 
<tr> 
    <td>${healthp.name}</td> 
    <td>${healthp.current_Reading > healthp.target ? healthp.current_Reading : healthp.target}</td> 
    <td>${healthp.measurementunit}</td> 
    <td>${healthp.target}</td> 
    <td>${healthp.recorddate}</td> 
</tr> 
</c:forEach> 
+0

고마워 내가 작동 여부를 확인하자 –

관련 문제