2

Example :

Select * from student where roll_no in ( 1,2,3 );

In student repository (Spring Boot):

@Query(value="Select * from student where roll_no in (?)",native =true)
List selectStudents(What do I give here ?)

Or is there any other way to implement this?

Divya S
  • 23
  • 1
  • 3

2 Answers2

1

If you want to use native query you can do it like below

@Query(value="select * from student where roll_no in (:rollNos)",native =true)
List<Object[]> selectStudents(@Param("rollNos") List<Integer> rollNos);

But I would recommend you to do it using JPA named query like below which is very easy to handle further as it gives you the result in entity format.

Student findByRollNo(List<Integer> rollNos);
AJcodes
  • 91
  • 4
0

You can just pass in a List, presumably if Integer or Long.

See: Spring CrudRepository findByInventoryIds(List<Long> inventoryIdList) - equivalent to IN clause

Matt
  • 2,063
  • 1
  • 14
  • 35