Skip to content
Advertisement

Thymeleaf URL with multiple variables

I’m using thymeleaf as template engine in my spring project.

My Problem is: I’m trying to submit my form to url that contains two variables, something like:

mysite/bla/{id}/bla/{id2} (two variables in url). So, I’m trying with this:

th:href="@{/bla/{id}/bla/{id2} (id=${object1.id}, id2=${object2.id})}"

The console shows the error:

“Skipping URI variable ‘id’ since the request contains a bind value with the same name.” So, someone has any ideia whats happening?

Update:

I changed the path to one variable, just to make some tests, and the problem still happening. The controller is very simple:

@PostMapping(value = "/{id}/bla")
    public ModelAndView salvarBug(MyObject object,
            @PathVariable("id") Long idObject1, Principal principal) {
                objectService.save(object);
                return new ModelAndView("redirect:"+idObject1);
    }

I updated the link in html too:

        <form method="POST" th:object="${object}"
            th:action="@{/{id}/bla (id=${object.id})}">

The real problem: an attribute was going null for database. Make no sense in this. I fix this.

Advertisement

Answer

Your solution uses the Standard Syntax and looks correct. You can try this workaround with concatenation:

<a th:href="${'/blah1/' + {object1.id} + '/blah2/' + {object2.id}}">some link</a>

UPDATE:

Try changing the name of the variable to something other than id. There’s a JIRA about this that I suspect may be causing an issue. You can also annotate with @ModelAttribute. You should also make sure you’re on the latest version of Spring.

Also, you can just do @PostMapping("/{id}/bla")

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement