Thymeleaf multiple submit button in one form

this works in my problem. use th:formaction on submit button this is work on how many you have submit button and this is also usefull for give more links to one form with different submit button

<form action="#"  class="form" th:action="@{'/publish-post/'+${post.id}}" method="post">
<input class="savebtn" type="submit" value="Save" th:formaction="'/save-post/'+${post.id}">
<input class="publish" type="submit" value="Publish Article">
</form>

You can create separate methods with different @RequestMappings using the params variable.

@RequestMapping(value="/edit", method=RequestMethod.POST, params="action=save")
public ModelAndView save() {}


@RequestMapping(value="/edit", method=RequestMethod.POST, params="action=cancel")
public ModelAndView cancel() {}

Instead of an if-case you could have a switch case, should you not want to take in every option as a new request mapping.

@RequestMapping(value="/edit", method=RequestMethod.POST)
public ModelAndView edit(@ModelAttribute SomeModel model, 
        @RequestParam(value="action", required=true) String action) {
    switch(action) {
        case "save":
            // do stuff
            break;
        case "cancel":
            // do stuff
            break;
        case "newthing":
            // do stuff
            break;
        default:
            // do stuff
            break;
    }
}