How to handle requests that includes forward slashes (/)?

前端 未结 7 1362
南旧
南旧 2020-11-30 05:40

I need to handle requests as following:

www.example.com/show/abcd/efg?name=alex&family=moore   (does not work)
www.example.com/show/abcdefg?name=alex&         


        
7条回答
  •  悲&欢浪女
    2020-11-30 06:01

    The first one is not working because you are trying to handle an entirely new URL which is not actually mapped your controller.

    www.example.com/show/abcd/efg?name=alex&family=moore   (does not work)
    

    The correct mapping for the above URL could be like the below code.

    @RequestMapping(value = {"/{mystring:.*}" , "/{mystring:.*}/{mystring2:.*}"}, method = RequestMethod.GET)
    public String handleReqShow(
            @PathVariable String mystring,
            @PathVariable String mystring2,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String family, Model model)     {
    

    I have tried the similar concept when my one controller is used to handle multiple types of request.

提交回复
热议问题