将蛇案转换成骆驼案-用Kotlin进行Spring数据投影

时间:2020-04-21 22:02:50

标签: spring kotlin spring-data-jpa spring-data

我正在将Spring数据与Kotlin一起使用。我有几个问题:

  1. 如何获取spring数据+ jpa,以将postgres上的蛇形案例中的列自动转换为Kotlin中的骆驼形案例。这在我的实体中效果很好,但在投影中却不起作用。在我的实体中,我不必为@Column提供名称,它可以正常工作。但这不是一个预测。这是我的代码:
interface CompanyShareholderTransactionsRepository: CrudRepository<CompanyShareholderTransactionsTable, UUID> {

    @Query("""
         select folio_no as folioNo, name, cert_no, dist_no_from, dist_no_to, date_acq  
         from company_shareholder_transactions txn  
         inner join company_shareholder_certs cert on txn.shareholder_certs_id = cert.id     
         inner join company_shareholders_info info on txn.shareholder_info_id = info.id
         where txn.company_id = :companyId and 
               txn.shareholder_certs_id = :certId
         order by txn.date_acq limit 1 
    """ , nativeQuery = true)
    fun getTransactionInfoByCertId(companyId: UUID, certId: UUID): TransactionInfo?
}

interface TransactionInfo {
    val folioNo: Int
    val name: String
    val cert_no: Int
    val distNoFrom: BigInteger
    val distNoTo: BigInteger
    val dateAcq: LocalDate
}

仅举一个有效的例子,
folioNo在sql中使用别名。
cert_no工作正常。
但是dist_no_from,dist_no_to和date_acq不会映射到TransactionInfo变量。

我正在寻找一种无需一直输入别名的方法。

  1. 如何使用数据类而不是接口。我想将TransactionInfo定义为数据类,以便可以向其添加其他方法和功能。

0 个答案:

没有答案