Spring Data jpa查询加入where where condition

时间:2017-12-16 05:09:58

标签: spring-data-jpa

我有两张桌子

  • RoleMasterLinkuserIdRoleId
  • RoleMasterRoleIdFunctionalRole

我需要实现

Select rm.FunctionalRole from RoleMaster rm join RoleMasterLink rml on rml.RoleId = rm.RoleId where rml.userId='yesh'

用户可以拥有多个roleId,我需要基于RoleId获取FunctionalRole

如何使用Spring Data Jpa实现这一点,经历了很多链接,但确实无法获得。

1 个答案:

答案 0 :(得分:1)

只需在Repository界面的@Query注释中添加查询:

@Query("Select rm.FunctionalRole from RoleMaster rm join RoleMasterLink rml on rml.RoleId = rm.RoleId where rml.userId= :userId")
String findFunctionalRole(String userId);