@RequestParam vs @PathVariable

前端 未结 7 910
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 06:22

What is the difference between @RequestParam and @PathVariable while handling special characters?

+ was accepted by @Re

7条回答
  •  情歌与酒
    2020-11-22 06:41

    @PathVariable - must be placed in the endpoint uri and access the query parameter value from the request
    @RequestParam - must be passed as method parameter (optional based on the required property)
     http://localhost:8080/employee/call/7865467
    
     @RequestMapping(value=“/call/{callId}", method = RequestMethod.GET)
     public List getAgentCallById(
                @PathVariable(“callId") int callId,
                @RequestParam(value = “status", required = false) String callStatus) {
    
        }
    
    http://localhost:8080/app/call/7865467?status=Cancelled
    
    @RequestMapping(value=“/call/{callId}", method = RequestMethod.GET)
    public List getAgentCallById(
                @PathVariable(“callId") int callId,
                @RequestParam(value = “status", required = true) String callStatus) {
    
    }
    

提交回复
热议问题