Java 如何在GET请求和GET映射中传递postman中的列表

Java 如何在GET请求和GET映射中传递postman中的列表,java,spring-boot,postman,Java,Spring Boot,Postman,我像这样使用邮递员向控制器发送一个id列表 localhost:8090/test/customer?id=1,2 @GetMapping public List<Customer> getCustomerListById(Optional<List<Integer>> customerId){ return getCustomerByIdService.getCustomerById(customerId.get()); } public inter

我像这样使用邮递员向控制器发送一个id列表

localhost:8090/test/customer?id=1,2
@GetMapping
public List<Customer> getCustomerListById(Optional<List<Integer>> customerId){

return getCustomerByIdService.getCustomerById(customerId.get());

}
public interface CustomerRepo extends CrudRepository<Customer , Integer>{

   public List<Customer> findByCustomerIdIn(List<Integer> customerId);

}
{
"timestamp": 1528884327211,
"status": 500,
"error": "Internal Server Error",
"exception": "java.util.NoSuchElementException",
"message": "No value present",
"path": "/test/customer"
}
像这样的控制器

localhost:8090/test/customer?id=1,2
@GetMapping
public List<Customer> getCustomerListById(Optional<List<Integer>> customerId){

return getCustomerByIdService.getCustomerById(customerId.get());

}
public interface CustomerRepo extends CrudRepository<Customer , Integer>{

   public List<Customer> findByCustomerIdIn(List<Integer> customerId);

}
{
"timestamp": 1528884327211,
"status": 500,
"error": "Internal Server Error",
"exception": "java.util.NoSuchElementException",
"message": "No value present",
"path": "/test/customer"
}

在url中,参数名为
customer
,但在控制器方法中,参数名为
customerId
,它们不相同

请尝试以下操作:-

获取:

一旦得到逗号分隔的ID,就可以拆分它们并执行需要执行的操作

代码:

@GetMapping(“/test/customer/{id}”)
公共列表getCustomerListById(@PathVariable字符串id)列表id,
{
....
}

通过在chrome上调试来检查您的请求。 当你们在浏览器上部署你们的应用程序时,你们会在开发者的工具中看到网络标签。
从那里选择您的Get请求并将其粘贴到Postman

对于
GetMapping
,api
getCustomerListById
的路径是什么?没有
路径
?查询字符串中的id和方法参数中的customerId之间没有映射。他可以向控制器添加“/customer”映射。如果他试图以一种安静的方式来做,他就不需要额外的路径@赫伦