Spring 부트 응용 프로그램에서 Model 클래스를 사용하여 속성으로 보낸 객체 목록 (댓글)을 필터링하려고합니다. JS 스크립트로 검색했지만 내 ID가 작동하지 않습니다.
내 비교할 수 있다면 누구나 어떤 생각 가지고 온도 에서 파일을 내와 CMT 에서 의견을 ? db " fileID "의 필드 가 temp.id 와 같은 주석을 표시 하고 싶습니다.
내 코드 :
<table div class="table table-light">
<thead>
<tr>
<th></th>
</tr>
</thead>
<tbody>
<tr th:each="temp : ${files}">
<td>
<div class="container col-sm-8 mt-2">
<div class="card card border-dark mb-2">
<div class="card-header">
<h5 class="card-title"><span th:text="${temp.title}"/></h5>
<p class="card-text">Added by me</p>
<p class="card-text"><small class="text-muted">Last updated <span th:text="${temp.data}"/></small></p>
</div>
<div class="card-body">
<img class="card-img-top" th:src="${temp.path}" alt="" style="size:auto;">
</div>
<div class="card-footer">
</div>
<div class="card-footer bg-transparent">
<table class="table table-light">
<thead>
<tr>
<td>
</td>
</tr>
</thead>
<tbody id="fileComments">
<tr th:each="cmt: ${comments}">
<td>
<span th:text="${cmt.userID}"/>
</td>
<td>
<span th:text="${cmt.comment}"/>
</td>
<td>
<span th:text="${cmt.date}"/>
</td>
</tr>
</tbody>
</table>
<form th:action="@{/comment}" th:object="${cmtModel}" style="size:auto" method="post">
<input type="hidden" th:value="${temp.id}" name="fileID" />
<input type="text" class="form-control" th:field="*{comment}" placeholder=" Add comment"/>
<button type="submit" class="button btn-success" style="border-radius: 10px"> Add </button>
</form>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
조건을 충족하는 주석 만 표시 하려면 다음 방법으로에 th:if
를 추가 하십시오 th:each
.
<tr th:each="cmt: ${comments}" th:if="${cmt.fileID} == ${temp.id}">
그러나 표준 구문을 사용하는 fileID 및 id 속성에 대한 getter가 필요합니다 (fileID에 문제가있을 수 있습니다.이 경우 fileId로 대체하므로 getFileId 및 getId 메소드가 있음).
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다