我使用@Query注释在spring存储库中执行查询。 但我想根据条件更改某些部分或创建一个新查询并传入@Query(“根据条件传递查询”)
这是我的查询
@Query("SELECT ds.symptom FROM DoctorSymptomsModel ds where ds.doctorId = :doctorId and ds.isMostUsed = :isMostUsed)
如果某些条件满足,则在查询中连接“ORDER BY createdDate”部分。
或者
我可以创建变量并在该变量中设置查询并设置为
String query = SELECT ds.symptom FROM DoctorSymptomsModel ds where
ds.doctorId = :doctorId and ds.isMostUsed = :isMostUsed
if(result){
query = SELECT ds.symptom FROM DoctorSymptomsModel ds where ds.doctorId =
:doctorId and ds.isMostUsed = :isMostUsed ORDER BY createdDate
}
//pass the query variable here
@Query(query)
List<String> findDoctorSymptomsModelList(@Param("doctorId") long doctorId,
@Param("isMostUsed") boolean isMostUsed);