0
votes

Comment puis-je utiliser une URL différente avec la même méthode dans le contrôleur avec @getMapping?

Il incapable de fonctionner sur les deux URL xxx

http : // localhost: 8080 / SeleniumExécutionTrending / Rapports / DuréeTrend / 427 -> Il n'appelle pas. HTTP: // localhost: 8080 / SeleniumExécutionTrending / Rapports / DuréeTrend / 427 / 7- - > il exécute.

Je veux exécuter les deux dans la même méthode


0 commentaires

3 Réponses :


0
votes
 @GetMapping(value= {"/durationtrend/{moduleId}","/durationtrend/{moduleId}/{records}"},produces= MediaType.APPLICATION_JSON_VALUE)
public List getExecutionDurationByModuleId(HttpServletRequest request) {
    Map map= (Map) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
    Integer moduleId=null,records=null;
    if(map!=null && map.get("moduleId")!=null){
        moduleId = Integer.valueOf(map.get("moduleId").toString());
    }
    if(map!=null && map.get("records")!=null){
        records = Integer.valueOf(map.get("records").toString());
    }
    System.out.println("moduleId:"+moduleId);
    System.out.println("records:"+records);
    //then you use modules and records , just judge  whether they are null?
    return executionDurationService.getExecutionDuration(moduleId,records);
}
I tried code above that  works . Try it , hopes that help you !

0 commentaires

0
votes

Voici votre problème est

@GetMapping("/durationtrend/{moduleId}")
public void getExecutionDurationByModuleId(@PathVariable("moduleId") Integer moduleId) {
    return executionDurationService.getExecutionDuration(moduleId);
    System.out.println(moduleId);
}

@GetMapping("/durationtrend/{moduleId}/{records}")
public void getExecutionDurationByRecords(@PathVariable("moduleId") Integer moduleId, @PathVariable("records") Integer records) {
    return executionDurationService.getExecutionDuration(moduleId, records);
    System.out.println(moduleId);
    System.out.println(records);
}


1 commentaires

Ici, les déclarations System.out.Println à des fins de test ... Cela m'a fonctionné



0
votes
@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);
     }

1 commentaires

Je pense que c'est mieux