4

I have to send two data from thymeleaf to controller like this in a th:href:

<table id="itemTable" class="deneme">
    <tbody>
    <tr th:each="item : ${list.items}">
        <td>
            <p th:text="${item.content}"/>
            <a th:href="@{/deleteItem/{listId}(listId=${list.id})/{itemId}(itemId=${item.id})}">
                <span>Delet‌​e</span>
            </a>
        </td>
    </tr>
    </tbody>
</table>

The controller is:

@RequestMapping("/deleteItem/{listId}/{itemId}")
public String deleteItem(Model model, @PathVariable(value = "listId") Integer listId, @PathVariable(value = "itemId") int itemId) {
    ...
    return "list";
}

itemId is coming with the true value but listId is coming as {listId}(listId=${toDoList.id})

What is the problem exactly? Please help me!

Mahozad
  • 18,032
  • 13
  • 118
  • 133
Utku Soytaş
  • 1,475
  • 2
  • 19
  • 30

2 Answers2

7

The syntax for multiple parameters looks like this:

<a th:href="@{/deleteItem/{listId}/{itemId}(listId=${list.id},itemId=${item.id})}"><span>Delet‌​e</span></a>
Metroids
  • 18,999
  • 4
  • 41
  • 52
2

You must define the @PathVariables in your Thymeleaf as comma-separated definitions within a single (paranthesis) So the syntax would be in the following form:

<a th:href="@{/deleteItem/{listId}/{itemId}(listId=${list.id},itemId=${item.id})}"><span>Delet‌​e</span></a>

Notice how the definitions are within the same paranthesis, only after PathVariable have been declared.