我正在使用 @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);