Spring request mapping wildcard exceptions

前端 未结 1 365
别跟我提以往
别跟我提以往 2021-01-04 04:23

Can I put /** wildcard in a middle of request mapping such as: \"/some/resource/**/somthing\"

In Spring 3 I can do this

@RequestMapping(\"/some/res         


        
相关标签:
1条回答
  • 2021-01-04 04:51

    I thinks it's not possible to use that ant style in url mapping as you require, because it will stop on the next path separator character '/'.

    I would suggest you to try 16.3.2.2. URI Template Patterns with Regular Expressions in order to map just the last part of the request (haven't tried this approach yet).

    Also you can match the rest of the request using PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, and apply some expression there. Check this post.

    Otherwise you should use request parameters to match that condition 16.3.2.6. Request Parameters and Header Values.

    You can narrow request matching through request parameter conditions such as "myParam", "!myParam", or "myParam=myValue". The first two test for request parameter presense/absence and the third for a specific parameter value. Here is an example with a request parameter value condition.

    In this case you will map something like that using params

    @RequestMapping(value = {"/some/resource/**"},  params="somthing")
    

    or use the annotation request parameter with not required attribute in method signature:

    public void test(@RequestParam(value = "somthing", required=false) String str) {
    
    0 讨论(0)
提交回复
热议问题