0

您如何处理映射 Postgres 结果记录的数组列?我有一个查询连接三个表,表 a、b 和 c。关系如下: a 0 到 n b b 1 到 1 c

询问:SELECT a.*, array_agg((b.*, c.*)) as b_list FROM a LEFT JOIN b ON b.id=ANY(a.b_ids) AND a.tenant_id=b.tenant_id LEFT JOIN c ON b.c_id=c.id AND b.tenant_id=c.tenant_id GROUP BY b.id, b.tenant_id

行映射器:

query.registerRowMapper(A.class, (rs, ctx) -> {
   
    //How do I handle the b_list??
    //I have tried the following
      Array bArray = rs.getArray("b_list");
      List<B> bDtos = new ArrayList<>();
      ResultSet resultSet = bArray != null ? bArray.getResultSet() : null;
      while (resultSet != null && !resultSet.last()) {
        bDtos.add(bDtoRowMapper.map(resultSet, ctx));
        resultSet.next();
      }
   
})
4

0 回答 0