我正在尝试使用连接 2 个表进行动态 sql 投影。这里 visibleColumns 是逗号分隔的字符串(我想在 SQL 选择语句中显示的动态列)。
QActive qActive = QActive.active;.
QCustomer qCustomer = QCustomer.customer;
QBaseCounterParty qBaseCounterParty = QBaseCounterParty.baseCounterParty;
StringExpression path = Expressions.stringPath(qActive, visibleColumns);
return JPQLQuery<String> resultSet = query.select(path).from(qActive).innerJoin(qActive.customer, qCustomer).on(qInvoice.customer.id.eq(qCustomer.id))
.innerJoin(qBaseCounterParty).on(qCustomer.id.eq(qBaseCounterParty.id)).where(queryDslSpec).orderBy(sort)
.offset(request.getPagination().getStartRow()).limit(request.getPagination().getRowsPerPage());
因此,每当我尝试运行它时,它都会使用 400 Bad Request 创建如下查询:
select active.docNumber, customerName from Active active inner join Customer customer with active.id = customer.id inner join BaseCounterParty baseCounterParty with customer.id = baseCounterParty.id order by active.transactionDate desc
我不确定如何从其他表中选择列,因为列完全是动态的。