spring-mvcget-mapping

How i can use different url with same method in Controller With @GetMapping?


it unable to run on both URL

@GetMapping(value= {"/durationtrend/{moduleId}","/durationtrend/{moduleId}/{records}"},produces=MediaType.APPLICATION_JSON_VALUE)
public List<ExecutionDurationResource> getExecutionDurationByModuleId(@PathVariable("moduleId") Integer moduleId,@PathVariable("records") Integer records) {    
    return executionDurationService.getExecutionDuration(moduleId,records); 
}

http://localhost:8080/seleniumexecutiontrending/reports/durationtrend/427 -->it not Call. http://localhost:8080/seleniumexecutiontrending/reports/durationtrend/427/7-->it executes.

I want to execute both in same method


Solution

  • @GetMapping(value= "/module-execution-trend",produces=MediaType.APPLICATION_JSON_VALUE) 
         public List<ExecutionResource> getExecutionResult(@RequestParam("moduleId") Integer moduleId,@RequestParam(name="records",required=false,defaultValue="10")  Integer records ) 
         {
            System.out.println(moduleId); 
            System.out.println(records); 
             return executionService.getModuleExecutionResult(moduleId,records);
         }