• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

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

 
Ranch Hand
Posts: 385
2
  • Mark post as helpful
  • send pies
  • 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: 24
5
Spring Java
  • Mark post as helpful
  • send pies
  • 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: 385
2
  • Mark post as helpful
  • send pies
  • 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: 1979
13
  • Mark post as helpful
  • send pies
  • 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: 385
2
  • Mark post as helpful
  • send pies
  • 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: 1979
13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Nathan,
% means 0, one or more characters.
https://www.w3schools.com/sql/sql_like.asp
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic