java - 如何使用 Spring Boot 在 API Get 方法 Endpoint 中传递多个 id

标签 java spring-boot spring-jdbc

我正在尝试在 GET 端点中传递多个 ID。 例如:如果我的数据库包含 10 名员工的详细信息(以 ID 作为主键),并且假设我想在某一特定点在端点中传递多个 id。这可能吗。 假设:

    http://localhost:8080/api/v/listempoloyee/{1,2,3,4}

{1,2,3,4} 是我们要从数据库中获取的员工 ID 列表。

使用 Spring Boot 和 JDBC 可以实现这一点吗?

最佳答案

这应该可以做到。

  @GetMapping("/{employeeIds}")
  public void trigger(@PathVariable String employeeIds) {
        List<String> ids = Arrays.asList(employeeIds.split(","));
        ..........
  }

现在您在 ids 字段中有一个 ID 列表。

关于java - 如何使用 Spring Boot 在 API Get 方法 Endpoint 中传递多个 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50639256/

相关文章:

spring - 消息转换异常 : Failed to resolve class name in Spring AMQP

java - 使用 simplejdbccall 执行存储过程的替代方法

java - 在 spring jpa 中调用返回没有实体的引用光标的函数

java - 如何将按钮对齐到水平面板的中心?

java - 如何使用 AbstractTableModel 在 JTable 上添加行?

java - 比较两个字符串的有效方法(字符顺序无关紧要)

java - 由于多个可能的 bean,Spring Boot Autowiring 泛型失败

java - 如何通过 Spring Rest api 生成 aws cloudfront url?

java - 由于 Android 6 上的权限,GCAM 8.4.0 连接失败

spring-boot - Azure环境变量不起作用: "Factory method ' dataSource' threw exception with message: URL must start with 'jdbc' "