首页 文章

使用@Query的2表查询的Spring JPA方法名称

提问于
浏览
0

EDITTED

好奇......我有一个自定义的Spring JPA查询,我不知道如何编写 .

我正在扩展PagingAndSortingRepository

@Query:select * from Table1 tb1 JOIN Table2 tb2 on tb1.id = tb2.tb1_id where tb2.personId =:personId and tb1.mainId =:mainId and tb2.status in(:statusList)

我不知道如何为此创建方法名称,因为它一直给我一个错误,说它无法在Table1中找到状态 .

我想像:public Page findByMainIdAndStatusInAndPersonId(@Param(“mainId”)Integer mainId,..........);会工作,但它告诉我它找不到状态 . 这是可以理解的,因为状态位于我正在尝试加入的Table2对象中 .

**Table1**
id
column1
column2
mainId
List<Table2> table2List

**Table2**
id
table1_id
status
person_id

表1和表2通过table2的table_id列链接 . 但是在Table1 JPA存储库中,我需要根据Table2中的条件获取所有Table1 .

我检查了“属性表达式”,但我没有 grab 如何编写jpa方法名称

多谢你们 :)

1 回答

  • 0

    经过一段时间环顾四周并尝试不同的事情......答案:

    如果要在Table2上查询,则需要将其添加到方法中:

    findBymainIdAndTable2List_StatusInAndTable2List_personId
    

    所以基本上添加列表名称后跟下划线和该表中的列名称 . 如果有人想添加更多,def感觉自由:D这就是我的工作方式

相关问题