KpsLok
KpsLok

Reputation: 903

Thymeleaf - How to add url to relative url

I have a form page into:

GET /admin/form

Instead of send to full relative path like:

th:action="@{/admin/form}"

i would like to send to:

th:action="@{**** I dont know how to set '/admin' from thymeleaf **** /form}"

In other words i want to get the path (/admin) programmatically. How can i do it and add '/form'?

Upvotes: 0

Views: 1555

Answers (1)

javasenior
javasenior

Reputation: 1815

If you want to get param from controller dynamically, just set a method like this:

  @RequestMapping(value = "form", method = RequestMethod.GET)
    public String messages(Model model) {
        model.addAttribute("param", "admin");
        return "form/";
    }

And then in html you can get it like this:

  <form th:action="@{/${param}/form}">

You can include parameters statically in the form of path variables like this :

<form th:action="@{/{param}/form(param='admin')}">

So if we formulize the path :

<form th:action="@{/staticpath/{dynamicpath}(dynamicpath=${type})}">

Upvotes: 1

Related Questions