• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Finding an entry that contains characters- Spring Boot/Data JPA

 
Ranch Hand
Posts: 447
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, I created a very basic project with Spring Boot where you put in a product and search for it, edit it, delete it, etc.  

However, the find by name only works if you type in the exact name.  Here is my controller class.  





How would I make it so that if the product was "shoes" but someone types in "shoe" it will still come up.   Do I need to make a custom query in the repository class?

I'm still very new to this, as you can tell, if you can help get me started with this, I'd appreciate it.
 
Author
Posts: 51
5
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Nathan. In the repository create a method that finds the records by your condition (E.g name contains :param). You can provide the search term then in your controller by a request parameter or a path variable.
You use that value further up to the repo. Cheers!
 
Nathan Milota
Ranch Hand
Posts: 447
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Laurentiu Spilca wrote:Hey Nathan. In the repository create a method that finds the records by your condition (E.g name contains :param). You can provide the search term then in your controller by a request parameter or a path variable.
You use that value further up to the repo. Cheers!



Would I have to create a custom query to do that?
 
Bartender
Posts: 2167
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nathan,
You may need to have an interface that extends JPARepository  or CrudRepository like this:


Reference:
https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#reference
 
Nathan Milota
Ranch Hand
Posts: 447
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Himai Minh wrote:Nathan,
You may need to have an interface that extends JPARepository  or CrudRepository like this:


Reference:
https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#reference



Thanks!  This worked.   If you don't mind me asking, what does the %: and then % mean?  
 
Himai Minh
Bartender
Posts: 2167
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Nathan,
% means 0, one or more characters.
https://www.w3schools.com/sql/sql_like.asp
 
Can you shoot lasers out of your eyes? Don't look at this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic