I have Spring Data REST repository that takes query parameters. It uses a PagingAndSortingRepository and looks like this:
[code language=”java”]
@RepositoryRestResource
@CrossOrigin(origins = "http://localhost:8000")
public interface IRestaurantRepository extends PagingAndSortingRepository<Restaurant, Long> {
public Page<Restaurant> findByNameContaining(String name, Pageable pageable);
}
[/code]
You would get an error if you were to execute the search command that is created for you with cURL.
[code language=”bash”]
$ curl -X GET http://localhost:8181/restaurants/search/findByNameContaining?name=Foo
{"cause":null,"message":"Unable to detect parameter names for query method com.coysoft.wingspecial.repository.IRestaurantRepository.findByNameContaining! Use @Param or compile with -parameters on JDK 8."}
[/code]
The error is pretty useful. It gives us two options for being able to use query parameters. The first is straightforward. Just modify the code like so:
[code language=”java”]
@RepositoryRestResource
@CrossOrigin(origins = "http://localhost:8000")
public interface IRestaurantRepository extends PagingAndSortingRepository<Restaurant, Long> {
public Page<Restaurant> findByNameContaining(@Param("name") String name, Pageable pageable);
}
[/code]
With this modification you’ll be able to get results. The second option involves modifying your build process. In my case, I am using Maven and I am in fact using Java 8. Therefore, I can modify the pom.xml to use this:
[code language=”xml” highlight=”16″]
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<fork>true</fork>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
<finalName>ROOT</finalName>
</build>
[/code]
Both work the same for me. Using @Param is more backwards compatible and verbose, but using -parameters would work across the board.
Thank you for sharing excellent informations. Your web-site is very cool. I’m impressed by the details that you have on this site. It reveals how nicely you understand this subject. Bookmarked this website page, will come back for extra articles. You, my pal, ROCK! I found simply the information I already searched all over the place and simply could not come across. What an ideal site.
Its good as your other blog posts : D, regards for putting up. “The rewards for those who persevere far exceed the pain that must precede the victory.” by Ted W. Engstrom.
Good V I should certainly pronounce, impressed with your web site. I had no trouble navigating through all the tabs as well as related info ended up being truly easy to do to access. I recently found what I hoped for before you know it at all. Reasonably unusual. Is likely to appreciate it for those who add forums or something, website theme . a tones way for your client to communicate. Nice task..
I visited a lot of website but I believe this one has got something special in it in it
Such a well-researched piece! It’s evident how much effort you’ve put in.
Your post resonated with me on many levels. Thank you for writing it!
I’m in awe of the way you handle topics with both grace and authority.
You’ve done a fantastic job of breaking down this topic. Thanks for the clarity!
I appreciate the unique viewpoints you bring to your writing. Very insightful!
The post has been incredibly helpful. Thank you for the guidance!
Always learning something new here, because apparently, I didn’t pay enough attention in school.
Thank you for consistently producing such high-quality content.
I admire the way you tackled this complex issue. Very enlightening!
This is one of the most comprehensive articles I’ve enjoy reading on this topic. Kudos!
Both informative and thought-provoking, as if my brain needed the extra workout.
Most comprehensive article on this topic. I guess internet rabbit holes do pay off.
Reading The work is like watching the sunrise, a daily reminder of beauty and new beginnings.
Reading The work is like catching up with an old friend; comfortable, enlightening, and always welcome.
You’ve opened my eyes to new perspectives, as if you knew the way to my curious heart.
Incredibly informative post! I learned a lot and look forward to more.
The take on hard to understand topics is like a smooth ride in a luxury car—comfortable, yet exhilarating.
Stumbling upon this article was the highlight of my day, much like catching a glimpse of a smile across the room.
The thought-provoking post has me looking forward to more. It’s like the intellectual equivalent of a second date.
This site is my breathing in, really great style and perfect articles.
Most comprehensive article on this topic. I guess internet rabbit holes do pay off.
You tackled a hard to understand issue with elegance and insight. I feel much more informed after reading The post.
The hard work you put into this post is as admirable as The commitment to high quality. It’s very attractive.
Such a well-researched piece! It’s evident how much effort you’ve put in.
The commitment to high quality content really shows. I’m always excited to read The work.
The ability to connect with readers is like a secret handshake, making us feel part of an exclusive club.
The finesse with which you articulated The points made The post a true pleasure to read.
This Writing is a treasure trove of knowledge. Thank you for The contributions!
The hard work you put into this post is as admirable as The commitment to high quality. It’s very attractive.
Articulated points with finesse, like a lawyer, but without the billable hours.
The Writing is a constant source of inspiration and knowledge. Thank you!
Amazed by The knowledge breadth, or what I’ve been mistaking for just good Googling skills.
The balance and fairness in The writing make The posts a must-read for me. Great job!
The approach to topics is like a master painter’s to a canvas, with each stroke adding depth and perspective.
The writing is a masterpiece. You managed to cover every aspect with such finesse.
Thank you for adding value to the conversation with The insights.
The insights light up my intellect like fireworks. Thanks for the show!
Thank you for shedding light on this subject. The perspective is refreshing!
Handling topics with grace and authority, like a professor, but without the monotone lectures.
Such a well-researched piece! It’s evident how much effort you’ve put in.
The writing style is captivating. Finally, something that can keep my attention longer than a TikTok video.
This post was a breath of fresh air. Thank you for The unique insights!
Reading The post was like going on a first date with my mind. Excited for the next rendezvous.
Shedding light on this subject like you’re the only star in my night sky. The brilliance is refreshing.
What a compelling read! The arguments were well-presented and convincing.
This comprehensive article had me hanging on every word, much like I would during a late-night chat.