• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 462
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: 66
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: 462
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: 2418
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: 462
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: 2418
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
 
it's a teeny, tiny, wafer thin ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic