Skip to content
Advertisement

How can i add data to th:action form

I have a spring-boot application. Full url that I need: localhost:8080/company/{companyName}/users?name={name}. In the beginning i choose company, for ex. : localhost:8080/company/google. The controller redirects me to the page with the form (company.html), where i type name. Controller:

JavaScript

In Data class i simply store company and name;

My form, where i type name:

JavaScript

So after i submit, the result url is localhost:8080/users?name=Example, i need localhost:8080/company/google/users?name=Example. How can i change it? I tried th:action=”@{/${data.company}/users}”, but ${data.company} interprets literally

Advertisement

Answer

Why do you want to use path and query parameters together? You can do it using either only path parameters or only query parameters.

As an answer to your question, you can try this:

JavaScript

Another option:

JavaScript

There are several ways to send your request to controller correctly.

  1. Send with query parameters:
JavaScript

which will be the output: ‘…./service?company=google&name=david’

  1. Use th:ref attribute:
JavaScript
  1. Put values inside the form and make a POST request.
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement