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!

2 Answers 2

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>
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah! Exactly true. Thanks.
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.