Search code examples
htmlcssspringspring-bootthymeleaf

Create hrefs with Thymeleaf


I have a SpringBoot app. + Thymeleaf, I have this piece of code:

and I want to create a link like this: /swans/3/tommy.html

so I create this piece of code:

<a th:href="@{/swans/{id}/{name}.html(id=${user.id},name=$(user.name))}" target="_blank">

but I have this error when init the app:.

Could not parse as expression: "@{/swans/{id}/{name}.html(id=${user.id},name=$(user.name))}"


Solution

  • You have the typo. For variables, you need to use curly brackets ...

    <a th:href="@{/swans/{id}/{name}.html(id=${user.id},name=${user.name})}" target="_blank">
    

    More information on Link URLs.