2 回答
TA贡献1853条经验 获得超9个赞
You can write the native query in the repository like this:
1)
@Query("SELECT t.column_name1 FROM table_name1 t WHERE t.column_name2 =:param")
List<String> getValue(@Param("param") String param);
OR
2)@Query("SELECT t.column_name1 FROM table_name1 t WHERE t.column_name2 = 'param'", nativeQuery=true)
List<String> getValue();
Or you can use NamedQuery and add the query in the model only.
for eg:
@Entity
@Table(name = "table_name1", schema="db_name")
@NamedQuery(name = "ENTITY.fetchParam",
query = "SELECT t.column_name1 FROM table_name1 t WHERE t.column_name2 =:param "
)
public class Employee {
}
And have same method in the repository like:
@Repository
public interface TestRepository extends JpaRepository<Employee,Long>, TestRepositoryCustom {
List<String> fetchParam(@Param("param") String param);
}
添加回答
举报