![](/img/trans.png)
[英]What is wrong in this Spring Boot controller method annotation? (the path of the request is defined at class level and the path variable at method)
[英]How to pass multiple path variables for spring boot controller class in GET method?
我試圖在GET方法中將多個路徑變量傳遞給我的控制器類,所以我通過POSTMAN給變量。當我嘗試單個變量時,它工作正常,但是對於兩個變量,我卻得到空結果。
這就是我通過POSTMAN localhost:8081 / specquestions / java / oops傳遞變量的方式
這里的“ java”是一個變量,“ oops”是另一個變量
我的Java控制器類
@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));
}
誰能建議我在哪里做錯了。
只需在控制器中為第二個參數添加@PathVariable,如下所示
@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));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.