Thymeleaf multiple submit button in one form

后端 未结 4 1617
时光说笑
时光说笑 2020-12-03 03:17

I have a fragment of HTML page with one form and 2 button:

4条回答
  •  独厮守ぢ
    2020-12-03 03:17

    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;
        }
    }
    

提交回复
热议问题