簡體   English   中英

Thymeleaf:如何在不創建新行集的情況下更新現有數據庫行?

[英]Thymeleaf: how to update existing database rows without creating new set of rows?

在我使用spring和thyme-leaf的Web應用程序中,數據庫中有一個表,需要由用戶更新。 在我的表格行下方找到。

<table class="table table-responsive">
    <thead>
    <tr>
        <th>From <a href="#"><i class="fa fa-sort-amount-asc"
                                aria-hidden="true"></i></a></th>
        <th>To <a href="#"><i class="fa fa-sort-amount-asc" aria-hidden="true"></i></a>
        </th>
        <th>th1(.min)</th>
        <th>th2</th>
        <th>th3</th>
        <th>th4 &#10095;</th>
        <th>th5</th>
        <th>th6</th>
        <th>th7</th>
        <th class="action">&nbsp;</th>
    </tr>
    </thead>
    <tbody>

    <tr th:each="ir, rowStat : *{invRows}">
        <input type="hidden"
               th:field="*{invRows[__${rowStat.index}__].fromTime}"/>
        <input type="hidden" th:field="*{invRows[__${rowStat.index}__].toTime}"/>
        <td><p th:text="${#dates.format(ir.fromTime,  'HH:mm')}"/></td>
        <td><p th:text="${#dates.format(ir.toTime,  'HH:mm')}"/></td>
        <td><input type="text"
                   th:field="*{invRows[__${rowStat.index}__].tvcDur}"/></td>
        <td><input type="text"
                   th:field="*{invRows[__${rowStat.index}__].priceR[0].price}"/>
        </td>
        <td><input type="text"
                   th:field="*{invRows[__${rowStat.index}__].priceR[1].price}"/>
        </td>
        <td><input type="text"
                   th:field="*{invRows[__${rowStat.index}__].priceR[2].price}"/>
        </td>
        <td><input type="text"
                   th:field="*{invRows[__${rowStat.index}__].lgPrice}"/></td>
        <td><input type="text"
                   th:field="*{invRows[__${rowStat.index}__].crPrice}"/></td>
        <td><input type="text"
                   th:field="*{invRows[__${rowStat.index}__].crSpots}"/></td>
        <td class="actions"></td>
    </tr>
    </tbody>
</table>  

參數已成功與mysql數據庫綁定。 但是問題是,不是更新行的現有值,而是每次保存表時一次又一次地添加整個行集。 如何更新表格?

編輯:我有以下下拉列表。 對於每個選擇,我想要一個表。 即我必須維護3表。 這個怎么做?

<select class="btn btn-default dropdown-toggle" data-toggle="dropdown"
        th:value = "${inventory.id}" id="channel" name="channel">
    <option th:value="Channel">Channel</option>
    <option th:value="ch1">ch1</option>
    <option th:value="ch2">ch2</option>
    <option th:value="ch3">ch3</option>
</select>

在表中,您需要添加對象的唯一標識符,然后當列表進入您的控制器時,存儲庫將知道是更新而不是創建。

<input type="hidden" th:field="*{invRows[__${rowStat.index}__].id}"/>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM