Search code examples
sqlspring-bootjpaspring-data-jpacrud

Multiple query parameters in Spring Data JPA


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.


Solution

  • 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);
    }