html百里香eaf直接在选项中发布

发布于 2025-02-11 18:16:34 字数 827 浏览 1 评论 0原文

我想直接推动选定的选项。但是我找不到解决方案。也许你可以帮我吗?

我有一个带有实体列表的桌子。我将为每个实体提供选择。但是我想直接保存选择。 我需要entry.id和cat.id。

这就是我所拥有的。

<form class="myForms" id="uploadCheckerForm" method="post" th:action="@{uploadStatus}">
  <table>
    <tr th:replace="fragment/form-fragments::checkerMainLine()"></tr>
    <tr th:each="entry : ${uploadList}">
      <td><select th:id="transactionCategory" th:name="transactionCategory">
        <option>Select</option>
        <option th:each="cat : ${transactionCategoryList}"
             th:text="${cat.name}" th:value="${cat.id}">
        </option></select>
      </td>
      <td th:text="${entry.Comment}">
    </tr>
  </table>
</form>

我该怎么办,它直接发布了此信息?

感谢您的帮助!

I want directly push the selected option. But i dont find a solution. Maybe u can help me?

I have a table with a list of entities. And i will offer a select for every entity. But i want to save the selection directly.
I need the entry.id and the cat.id.

This is what i have.

<form class="myForms" id="uploadCheckerForm" method="post" th:action="@{uploadStatus}">
  <table>
    <tr th:replace="fragment/form-fragments::checkerMainLine()"></tr>
    <tr th:each="entry : ${uploadList}">
      <td><select th:id="transactionCategory" th:name="transactionCategory">
        <option>Select</option>
        <option th:each="cat : ${transactionCategoryList}"
             th:text="${cat.name}" th:value="${cat.id}">
        </option></select>
      </td>
      <td th:text="${entry.Comment}">
    </tr>
  </table>
</form>

What have i to do, that it directly post this infos?

Thanks for help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

在巴黎塔顶看东京樱花 2025-02-18 18:16:34

我将您的输入的一些唯一标识符附加到您的&lt; select的名称中,然后使用某种分离器,然后在后端上接受形式数据。这样的Kinda:

html

<form class="myForms" id="uploadCheckerForm" method="post" th:action="@{uploadStatus}">
  <table>
    <tr th:replace="fragment/form-fragments::checkerMainLine()"></tr>
    <tr th:each="entry : ${uploadList}">
      <td><select id="transactionCategory" th:name="'transactionCategory_' + ${entry.guid}">
        <option>Select</option>
        <option th:each="cat : ${transactionCategoryList}"
             th:text="${cat.name}" th:value="${cat.id}">
        </option></select>
      </td>
      <td th:text="${entry.Comment}">
    </tr>
  </table>
</form>

控制器

@PostMapping( "/uploadStatus" )
public String uploadStatus( @RequestParam Map<String, Long> params ) {
    for ( Map.Entry<String, Long> entry : params.entrySet() ) {
        if ( entry.getKey().startsWith( "transactionCategory_" ) ) continue; // skip

        Long entryId = Long.parseLong( entry.getKey().replace( "transactionCategory_", "" ) ); // get entry ID

        SomeDAO.instance().uploadStatus( entryId, entry.getValue() ); // do what you need to do with id of entry and chosen category ID
    }

    return "redirect:/";
}

I would append some unique identifier of your entry to the name of your <select> with some sort of separator and then accept form data on backend to a Map. Kinda like this:

HTML

<form class="myForms" id="uploadCheckerForm" method="post" th:action="@{uploadStatus}">
  <table>
    <tr th:replace="fragment/form-fragments::checkerMainLine()"></tr>
    <tr th:each="entry : ${uploadList}">
      <td><select id="transactionCategory" th:name="'transactionCategory_' + ${entry.guid}">
        <option>Select</option>
        <option th:each="cat : ${transactionCategoryList}"
             th:text="${cat.name}" th:value="${cat.id}">
        </option></select>
      </td>
      <td th:text="${entry.Comment}">
    </tr>
  </table>
</form>

Controller

@PostMapping( "/uploadStatus" )
public String uploadStatus( @RequestParam Map<String, Long> params ) {
    for ( Map.Entry<String, Long> entry : params.entrySet() ) {
        if ( entry.getKey().startsWith( "transactionCategory_" ) ) continue; // skip

        Long entryId = Long.parseLong( entry.getKey().replace( "transactionCategory_", "" ) ); // get entry ID

        SomeDAO.instance().uploadStatus( entryId, entry.getValue() ); // do what you need to do with id of entry and chosen category ID
    }

    return "redirect:/";
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文