I would like to write a REST api to do a IN query
as follows:
@GetMapping("/student")
public ResponseEntity<List<Student>> getStudents(
@RequestParam String searchQuery) {
return ResponseEntity.ok().body(studentService.searchStudents(searchQuery));
}
Associated service implementation is as follows:
public List<Student> searchStudents(String queryParam) {
String baseQuery = "SELECT * from student ";
if(!queryParam.isBlank()) {
/*I cannot understand what should I write here to form the final query as follows:
SELECT *from student where id in (id1, id2,..);
Here id1, id2.. should from query param */
}
...
}
As I mentioned above, I cannot figure out how will I pass the query param in the REST API and parse it downstream to form the final IN
query for the underlying DB table.