我希望能够执行过滤可用行的查询,如果不可用,则返回所有结果。如何在纯HQL
中完成此操作,而不使用Criteria
?
下面的代码段会编译,但查询不会返回任何结果。
@Repository
public interface ArticleRepository extends CrudRepository<Article, Long> {
@Query("FROM Article a " +
"JOIN a.manufacturer m " +
"WHERE " +
"(:search_term IS NULL OR :search_term = '' OR a.description LIKE CONCAT(:search_term, '%')) AND " +
"(:manufacturer_id IS NULL OR m.id = :manufacturer_id) " +
"ORDER BY f.priority DESC")
Page<Firmware> search(@Nullable @Param("search_term") String searchTerm,
@Nullable @Param("manufacturer_id") Long manufacturerId,
Pageable pageable);
}