我有两个参数说明国家实体的名称和描述。
我编写了如下的JPA查询:
@Query("select s from State s where (:name is null or s.name = :name) or (:desc is null or s.desc=:desc)")
List<State> fetchStates(@Param("name") String name, @Param("desc") String description, Pageable pageable);
生成的SQL查询:
select state0_.state_id as state1_24_, state0_.created_date as creation2_24_, state0_.desc as descript3_24_, state0_.name as name4_24_ from state state0_ where ? is null or state0_.name=? or ? is null or state0_.desc=? order by state0_.name desc limit ?
我想,如果我们有多个参数,我们就无法编写动态查询来获得所需的结果。如果我错过了我的假设,请告诉我。我是JPA的新手。