简体   繁体   English

如何在GET方法中为Spring Boot Controller类传递多个路径变量?

[英]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. 我试图在GET方法中将多个路径变量传递给我的控制器类,所以我通过POSTMAN给变量。当我尝试单个变量时,它工作正常,但是对于两个变量,我却得到空结果。

This is how i am passing variables through POSTMAN localhost:8081/specquestions/java/oops 这就是我通过POSTMAN localhost:8081 / specquestions / java / oops传递变量的方式

here 'java' is one variable and 'oops' is one more variable 这里的“ java”是一个变量,“ oops”是另一个变量

My java controller class 我的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));

}

Can any one please suggest me where i did mistake. 谁能建议我在哪里做错了。

Just add @PathVariable for second parameter in controller like below 只需在控制器中为第二个参数添加@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.

相关问题 这个 Spring Boot controller 方法注释有什么问题? (请求的路径在 class 级别定义,路径变量在方法中定义) - 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) 如何在 Spring 引导控制器中获取给定路径的 URL? - How to get URL given path in Spring boot Controller? 如何使用 Spring Boot 在 API Get 方法 Endpoint 中传递多个 id - How to pass multiple ids in API Get method Endpoint using Spring Boot 如何在 Spring 控制器的 Url 中传递多个变量? - How can i pass multiple variables in the Url for the Spring controller? 如何使用Spring Boot在Post方法中传递Json数据? 我想传递几个变量,并在另一个java类中使用该变量 - how can i pass Json data in a Post method using spring boot? I want to pass few variables and use that variables in a different java class Spring Boot Controller不支持请求方法&#39;GET&#39; - Request method 'GET' not supported in Spring Boot Controller Spring Boot-获取控制器方法名称 - Spring Boot - Get controller method name 如何将参数传递给 Spring 引导 REST Controller? - How to pass an argument to a Spring Boot REST Controller? 如何在Spring Boot控制器类中传递参数(应用程序正在使用Spring Security) - How to pass parameters in Spring Boot controller class (app is using Spring Security) 将 @Transactional 方法结果从 Service 传递到 Controller 层 Spring Boot - Pass @Transactional method result from Service to Controller Layer Spring Boot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM