1

So, my problem is I have a api I am creating an I am getting data from database. So, when I do GET localhost:8080/myapp/jobs?autocomplete=0120 (which 0120 is the full value of the jobs code to show that data, which it does show that data). But, when I do localhost:8080/myapp/jobs?autocomplete=012 it wont show what data it has for 012 to display in json. Can anyone help me solve this issue with my code below. thanks!

  @RequestMapping(value = "/jobs")
    public List<AutoComplete> getSalary( @PathVariable("autocomplete") String autocomplete, @RequestParam(value = "jobClassCd", defaultValue = "1502") String jobClassCd) {

        return autoCompleteService.retrieveSalary(jobClassCd);
    }

1 Answers1

0

I think your best bet would be to write a query that does something like

select * from AutoComplete where jobClassCd like 012%

Change your repository method as below.

@Repository 
public interface AutoCompleteRepository extends CrudRepository<AutoComplete, String> { 

    @Query("select e from AutoComplete e where jobClassCd like ':jobClassCd%'") 
    List<AutoComplete> findByJobClassCd(@Param("jobClassCd") String jobClassCd); 


    @Query("select e from AutoComplete e") 
    public Stream<AutoComplete> streamAll(); 
}
Vishal Patel
  • 554
  • 6
  • 15