2015-06-04 25 views
7

devo sottostante Codice in mio controller:@PathVariable e @RequestParam non lavorare insieme

@RequestMapping(value = "/child/{nodeId}/{relType}",method = RequestMethod.GET, produces=MediaType.APPLICATION_JSON)  
    public Iterable<Node> getConnectedNodes(@RequestParam("page")int page, @RequestParam("size")int size, @PathVariable("nodeId") String nodeId, @PathVariable("relType") String relType) { 
     return nodeService.getConnectedNodes(nodeId, relType,page,size);  
    } 

E questo è l'URL API sto colpendo

http://localhost:8080/node/child/e17a64ff-dc2b-49b1-a995-67dba9413d67/Collegues?page=0&size=1

Qui in modalità debug posso vedere i valori delle variabili di percorso, ad esempio nodeId e relType ma non è possibile visualizzare i valori della richiesta param pagina e dimensioni che sto passando attraverso la mia richiesta nell'URL sopra.

Cosa c'è che non va con @RequestParam? Per favore aiuto.

risposta

2

Puoi provare con frammento di seguito:

@RequestMapping(value = "/child/{nodeId}/{relType}",method = RequestMethod.GET, produces=MediaType.APPLICATION_JSON)  
     public Iterable<Node> getConnectedNodes(@RequestParam(value="page", required=false) int page, @RequestParam(value="size", required=false) int size, @PathVariable("nodeId") String nodeId, @PathVariable("relType") String relType) { 
      return nodeService.getConnectedNodes(nodeId, relType,page,size);  

} 
Problemi correlati