Preloader image
DDD

자바

타임 리프 class, id, if, onClick, data-param 값에 적용 - 단어 + 변수 예제

작성자 관리자 (admin)
조회수 333
입력일 2023-05-24 08:28:14

-- html 그대로 출력|

<th:block th:utext="<span style='color:red;'>Color</span>"></th:block>
출력 : Color

-- 타임 리프 class, id 값에 적용 - 단어 + 변수 예제

<th:block th:each="row : ${asia}">
  <tr>
    <th class="pc" th:text="${row.dps_num}"></th>
  </tr>
  <tr th:attr="class=${'tr_' + row.dps_num}">
    <td colspan="11" th:attr="class=${'open_class person_' + row.dps_num}"></td>
  </tr>
</th:block>

-- 조건에 따라 class 값을 변경

<span th:attr="class=${condition ? 'base condition-true' : 'base condition-false'}">
  조건에 따라 class 값을 변경

</span>

-- Javascript:OnClick

<div th:onclick="'clk_event1('+ ${item.menuid} + ')'">클릭</div>

-- Javascript

<script th:inline="javascript">

  let articleArray = new Array();
  let article = new Object();
  
  /*[# th:each="article : ${articleList}"]*/
  article.id =  /*<${article.id}>*/;
  article.title =  /*<${article.title}>*/;
  article.content =  /*<${article.content}>*/;
  articleArray.push(article);
  /*[/]*/

</script>

-- data-param 적용

<span class="bi bi-zoom-in detail" th:data-num="${row.dps_num}"></span>

-- 문자열 자르기 (일자 만들기)

<td th:text="${#strings.substring(row.dps_reserve,0, 11)}"></td>

-- 단일 Object 출력

<th:block th:object="${asia}">
  <span th:text="*(dps_name}">
  <spsn th:text="*(dps_server}">
</th:block>

-- Loop 시 자체 카운팅

<th:block th:each="uuu, row : ${sel_server}"> <!-- sel_server object -->
    <pre>
    index = <span th:text="${row.index}"></span>
    count = <span th:text="${row.count}"></span>
    size = <span th:text="${row.size}"></span>
    even? = <span th:text="${row.even}"></span>
    odd? = <span th:text="${row.odd}"></span>
    first? = <span th:text="${row.first}"></span>
    last? = <span th:text="${row.last}"></span>
    current = <span th:text="${row.current.cce_hname}"></span>
    uuu = <span th:text="${uuu.cce_hname}"></span>
    </pre>
</th:block>

<th:block th:each="dat, row : ${sel_server}"> <!-- sel_server object -->
    <th:block th:if="${ row.count == 1 }">
        <li th:data-filter="${dat.cce_num}" th:attr="class=${'loc ' + dat.cce_num} + ' filter-active'" th:text="${dat.cce_hname}"></li>
    </th:block>
    <th:block th:if="${ row.count != 1 }">
        <li th:data-filter="${dat.cce_num}" th:attr="class=${'loc ' + dat.cce_num} + '              '" th:text="${dat.cce_hname}"></li>
    </th:block>
</th:block>

 

 

 

^