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.
Such a well-researched piece! It’s evident how much effort you’ve put in.
The breadth of The knowledge is amazing. Thanks for sharing The insights with us.
The words are like a melody, each post a new verse in a song I never want to end.
Reading The post was like going on a first date with my mind. Excited for the next rendezvous.
The passion you pour into The posts is like a flame, igniting curiosity and warming the soul.
The piece was both informative and thought-provoking. Thanks for the great work!
The creativity and insight left a big impression on me. Fantastic job!
I’m officially a fan of The work. It’s like having a crush, but intellectually stimulating.
Testament to The expertise and hard work, or The ability to make me feel utterly unaccomplished.
This post is a testament to The expertise and hard work. Thank you!
Stumbling upon The article was a highlight of my day. It was just what I needed to read.
The post resonated with me on many levels. Thank you for writing it!
The arguments were as compelling as The online persona. I’m totally sold—and not just on The ideas.
I look forward to The posts because they always offer something valuable. Another great read!
I hafe been browssing on-line greater than thrree hours lately,
yeet I neverr dioscovered anyy attention-grabbing article like
yours. It is beaautiful valoue sufficient forr me. In mmy view, iif
alll webmasterds and bloghers mare just rigt
conrent as you probaly did, the web will liukely be much more usewful than eber before.
A go-to resource, like a library but without the late fees.
I’m always excited to see The posts in my feed. Another excellent article!
Beautifully written and incredibly informative, The post has made a lasting impression on me. Thank you for sharing The thoughts.
The post resonated with me on many levels. Thank you for writing it!
I loved the fresh take on the state of the country. The points resonated with me deeply.
The creativity and intelligence shine through this post on the state of the country. Amazing job!
You have a gift for explaining things in an understandable way on the state of the country. Thank you!
Remember, the key with flirtatious comments is to keep them light-hearted, respectful, and ensure they’re taken in the spirit of fun and admiration.
The way you break down ideas is like a chef explaining a recipe, making hard to understand dishes seem simple.
You’ve opened my eyes to new perspectives. Thank you for the enlightenment!
The insights are as invigorating as a morning run, sparking new energy in my thoughts.
The posts are like a secret garden of knowledge. I’m always excited to see what’s blooming.
The way you break down ideas is like a chef explaining a recipe, making hard to understand dishes seem simple.
Reading The work is like gazing at a masterpiece; every detail contributes to a breathtaking whole.
The passion you pour into The posts is like a flame, igniting curiosity and warming the soul.
The insights have added a lot of value to my understanding. Thanks for sharing.
Brilliant piece of writing. It’s like you’re showing off, but I’m not even mad.
I’m so grateful for the information you’ve shared. It’s been incredibly enlightening!
The Charlotte Dog Park is such a gem—plenty of space for my dog to stretch his legs and make new furry friends.
Thank you for shedding light on this subject. The perspective is refreshing!
Shedding light on this subject like you’re the only one with a flashlight. Refreshing to see someone who thinks they have all the answers.
The Writing is like a trusted compass, always pointing me in the direction of enlightenment.
Explore high quality cosmetic ingredients, personal care chemicals, and skincare raw materials in India. We offer wholesale cosmetic ingredients, essential oils, and custom skincare solutions. Trusted cosmetic chemical manufacturers and suppliers for your cosmetic product needs.
This post is a testament not only to The expertise but also to The dedication. Truly inspiring.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.