0

need to bind url dynamically in @RequestMapping.

url:/v3/api/overtime/config/policy-edit/108/0
dynamic pathUrl: api/overtime/config/policy-edit

i have checked as pathvariable--

@RequestMapping(value = "/{pathUrl}/{policyId}/{pageId}")

getting error --

org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported
    at org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.handleNoMatch(RequestMappingInfoHandlerMapping.java:200) ~[spring-webmvc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod(AbstractHandlerMethodMapping.java:419) ~[spring-webmvc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:365) ~[spring-webmvc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:65) ~[spring-webmvc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandler(AbstractHandlerMapping.java:401) ~[spring-webmvc-5.1.9.RELEASE.jar:5.1.9.RELEASE]

then i am check with regular expression but still not able to map.

@RequestMapping(value = "/v3/{pathUrl:[/[a-z][A-Z]*-]}/{policyId}/{pageId}")

any suggestion.Thanks.

M. Deinum
  • 115,695
  • 22
  • 220
  • 224
Basavaraj
  • 1,081
  • 1
  • 11
  • 21
  • 2
    What exactly do you mean with "not working" and "not able"? Do you get an error from the compiler, or at runtime? If so, then what error do you get? Show us your code - without seeing your code it's impossible to tell what's wrong with it. – Jesper Nov 21 '19 at 07:54

1 Answers1

0

Without seeing your code is really hard to tell what's wrong with your problem.

But i did an example of code, which is cover your question and provide possible solution.

package com.example;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/test_controller")
public class TempContrl {

    @RequestMapping("/{path}/{value}/{variable}")
    public void test(@PathVariable String path, @PathVariable String value, @PathVariable String variable){
        System.out.println(path);
        System.out.println(value);
        System.out.println(variable);
    }
}
  • this work fine,if path value is only a one word like 'policy-edit',but in my case path value is like 'api/overtime/config/policy-edit'. – Basavaraj Nov 22 '19 at 05:19