Hql基本可以与SQL对应起来,建议尽量用hql,Hql比较方便DBA做优化
实际情况 ,可以以哪个简洁用哪个。
1、问号占位
@Query("SELECT it FROM xxxxx.Zqxxgl it WHERE it.ztId=?1 and it.zwrxxId=?2 ") List<Zqxxgl> findAllByZtIdAndZwrxxId( int ztId, int id);
2、@Param注解绑定值
@Query("SELECT it FROM xxxxx.Zqxxgl it WHERE it.ztId=:ztId and it.zwrxxId=:zwrxxId ") List<Zqxxgl> findAllByZtIdAndZwrxxId(@Param("ztId") int ztId, @Param("zwrxxId") int id);
3、集合
@Query("SELECT it FROM xxxxx.Zwrxxb it WHERE it.shztOne=true and it.id in (:allZwrxxIs)")
List<Zwrxxb> findAllByShztOneAndIdIn(@Param("allZwrxxIs") List<Integer> allZwrxxIs);
@Query("SELECT it FROM wolverine.Zwrxxb it WHERE it.shztOne=true and it.id in ?1")
List<Zwrxxb> findAllByShztOneAndIdIn( List<Integer> allZwrxxIs);