我有兩個表由兩個實體表示:的一個表/實體的查詢使用結果查詢另一個實體/表
@Entity
public class HostEntity
{
@NotNull
private String myGroup;
@Id
@NotNull
private String host;
@NotNull
private long inGroupSince;
}
和
@Entity
public class GroupEntity
{
@NotNull
private String groupId;
@Id
@NotNull
private String propertiesStr;
}
我會爲每個crudRepository實體/表。
因此,考慮到兩個數字,開始時間和finishTime,和兩個字符串,stringA和stringB第一 - 讓所有HostEntity.myGroup(可以稱之爲利斯塔),使得HostEntity.inGroupSince是startTime和finishTine之間,然後,返回所有GroupEntity.groupId這樣GroupEntity.groupdId是利斯塔和GroupEntity.propertiesStr containt stringA和StringB
w ^帽子將是實現這一目標的最佳方式?我可以在一個查詢中做到這一點?
林在春季啓動正與crudRepository還挺新的。
我可以使用@query註釋在repostiroy,比如我下面的代碼:
@Repository
@Profile(Constants.SPRING_PROFILE_DEVELOPMENT)
public interface IGroupsRepositoryDev extends IGroupsRepository
{
@Query("SELECT j FROM GroupEntity j WHERE LOWER(j.propertiesStr) LIKE %?1% and LOWER(j.propertiesStr) LIKE %?2% and LOWER(j.propertiesStr) LIKE %?3%"
+ " and LOWER(j.propertiesStr) LIKE %?4% and LOWER(j.propertiesStr) LIKE %?5% and LOWER(j.propertiesStr) LIKE %?6% and LOWER(j.propertiesStr) LIKE %?7%"
+ " and LOWER(j.propertiesStr) LIKE %?8% and LOWER(j.propertiesStr) LIKE %?9% and LOWER(j.propertiesStr) LIKE %?10% and LOWER(j.propertiesStr) LIKE %?11% ")
List<UUID> findByProperties(String property1,String property2,String property3,String property4,String property5,String property6
,String property7,String property8,String property9,String property10,String property11);
}
其回報每一位GroupEntity這樣GroupEntity.propertiesStr containts它裏面
11串UPDATE
我用以下建議如下:
@Query(" SELECT groupId from GroupEntity where groupId IN (SELECT myGroup FROM HostEntity WHERE inGroupSince > ?12 AND inGroupSince < ?13) "
+ "AND LOWER(propertiesStr) LIKE %?1% and LOWER(propertiesStr) LIKE %?2% and LOWER(propertiesStr) LIKE %?3%"
+ " and LOWER(propertiesStr) LIKE %?4% and LOWER(propertiesStr) LIKE %?5% and LOWER(propertiesStr) LIKE %?6% and LOWER(propertiesStr) LIKE %?7%"
+ " and LOWER(propertiesStr) LIKE %?8% and LOWER(propertiesStr) LIKE %?9% and LOWER(propertiesStr) LIKE %?10% and LOWER(propertiesStr) LIKE %?11% ")
List<String> findByPropertiesBetweenTime(String property1,String property2,String property3,String property4,String property5,String property6
,String property7,String property8,String property9,String property10,String property11,long st,long ft);
我把它放在GroupEntity存儲庫中,但它不工作。我究竟做錯了什麼 ?
感謝,但在庫我應該把它?它沒有關係? – nadavgam
對不起,我不是那種熟悉Spring Boot的人,但在你的例子中使用上面的@query註釋查詢似乎是合理的。 – hartwecm