![](/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.