devxlogo

How to Pass Parameters in @Query

How to Pass Parameters in @Query

Passing parameters to an SQL query written via @Query can be done via @Param or via positional parameters:

// via @Param@Query(value = "SELECT p FROM Product p WHERE p.department=:department")List fetchByDepartment(@Param("department") String department);// via positional parameters@Query(value = "SELECT p FROM Product p WHERE p.department=?1")List fetchByDepartment(String department);

devx-admin

Share the Post: