-1

Generally the code is -->

Image of code, click here to see the code!

I want that method which is hardcoded as "post" need to come from greeting object eg. (greeting.method)

How can I achieve that any suggestions?

  • I don't understand your question (it is not very well formulated). If you want to save your object from thymeleaf via post request here is a good guide https://www.baeldung.com/thymeleaf-in-spring-mvc – J Asgarov Jul 18 '20 at 17:36
  • Hi asgarav, thankyou for reply, what i want to say is in form (HTML) for attributes action and url i want value to get it from object not hardcoded eg.
    instead of that can i have something like
    [this is sample which i'm looking for ]
    – Shirish Patil Jul 19 '20 at 01:52

1 Answers1

0

So just to make it clear, you want to read the url action and method from a variable, instead of hardcoding them in thymeleaf

In that case that is actually very simple:

  1. Pass url and method variables to the model by defining the following in your controller

    @ModelAttribute("url") public String url() { return "foo/bar"; }

    @ModelAttribute("method") public String method() { return "POST"; }

  2. Define the url and method with thymeleaf: <form th:action="${url}" th:method="${method}" ...>

J Asgarov
  • 2,526
  • 1
  • 8
  • 18