Spring - is possible to give same url in request mapping of post method?

后端 未结 3 1590
情歌与酒
情歌与酒 2021-01-21 18:12

Is that possible to use same url in request mapping for two different post method, only request body differs.

3条回答
  •  一个人的身影
    2021-01-21 18:50

    Yes you can do that but you need to specify unique parameters signature in RequestMapping annotation:

    public class MyController {
    
    @RequestMapping(method = RequestMethod.POST, params = {"!name", "!name2"})
    public String action(HttpServletRequest request, HttpServletResponse response){
        // body
    }
    
    @RequestMapping(method = RequestMethod.POST, params = "name")
    public String action(HttpServletRequest request, HttpServletResponse response,
                            @RequestParam(value = "name", required = true) String name) {
        // body
    }
    
    }
    

    `

提交回复
热议问题