Roy
Roy

Reputation: 910

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.

Upvotes: 4

Views: 16759

Answers (1)

Roy
Roy

Reputation: 910

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));

    }

Upvotes: 11

Related Questions