Home > Software design >  Multiple query parameters in Spring Data JPA
Multiple query parameters in Spring Data JPA

Time:11-26

What am I doing wrong?

Repository:

@Query(value = "SELECT * FROM agenda WHERE substring(data,1,10) IN (:data0,:data1)", nativeQuery = true)
List<AgendaModel> find(String data0,String data1);

Controller:

@RequestMapping(value="/agenda/clone/{data0}/{data1}", method=RequestMethod.GET)
public @ResponseBody List<AgendaModel> clone(@PathVariable String data0, String data1){
    return actions.find(data0,data1);
}

It works, but send me back just the first data result. For example if I try to use "/agenda/clone/2022-11-24/2022-11-25" I get the values from 2022-11-24 and no values from 2022-11-25.

CodePudding user response:

I can see @PathVariable annotation is missing for data1. Please write method like this and try again.


@RequestMapping(value="/agenda/clone/{data0}/{data1}", method=RequestMethod.GET)
public @ResponseBody List<AgendaModel> clone(@PathVariable String data0, @PathVariable String data1){
    return actions.find(data0,data1);
}

  • Related