How to Pass Multiple Path Variables for Spring Boot Controller Class in Get Method?

i am trying to pass multiple path variables to my controller class in GET method, so i am giving variables through POSTMAN, When i tried for single variable it's working fine, but for two variables i am getting empty result.

This is how i am passing variables through POSTMAN localhost:8081/specquestions/java/oops

here 'java' is one variable and 'oops' is one more variable

My java controller class

@RequestMapping(method=RequestMethod.GET,value="/specquestions/{subject}/{topic}")
public ResponseEntity<List<QuestionBank>> getSpecificQuestions(@PathVariable String subject,String topic) {

    return ResponseEntity.ok( questionBankService.getSpecificquestions(subject,topic));

}

Can any one please suggest me where i did mistake.

2

1 Answer

Just add @PathVariable for second parameter in controller like below

@RequestMapping(method=RequestMethod.GET,value="/specquestions/{subject}/{topic}")
    public ResponseEntity<List<QuestionBank>> getSpecificQuestions(@PathVariable String subject,@PathVariable String topic) {

        return ResponseEntity.ok( questionBankService.getSpecificquestions(subject,topic));

    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest