-
Notifications
You must be signed in to change notification settings - Fork 43
Home
Spring Search provides advanced search capabilities to a JPA entity
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Spring Search provides a simple query language to perform advanced searches for your JPA entities.
Let's say you manage cars, and you want to allow API consumers to search for:
- Cars that are blue and that were created after year 2006 or whose model name contains "Vanquish"
- Cars whose brand is "Aston Martin" or whose price is more than 10000$
You could either create custom repository methods for both these operations, which works well if you know in advance which fields users might want to perform searches on. You could also use spring-search that allows searching on all fields, combining logical operators and much more.
Please note that providing such a feature on your API does not come without risks such as performance issues and less clear capabilities for your API. This article summarizes these risks well.
To get a local copy up and running follow these simple steps.
This is an example of how to list things you need to use the software and how to install them.
- npm
npm install npm@latest -g
- Clone the repo
git clone https:://github.com/sipios/spring-search.git
- Install NPM packages
npm install
- Make the library available
mvn install #inside the spring-search folder
- Add the repo to your project inside your
pom.xml
file
<dependency>
<groupId>com.sipios</groupId>
<artifactId>spring-search</artifactId>
<version>0.0.4-SNAPSHOT</version>
</dependency>
- Import the library in your controller
import com.sipios.springsearch.anotation.SearchSpec;
- Use it (see Usage for various examples)
@GetMapping("someMapping")
fun yourFunctionNameHere(@SearchSpec specs: Specification<yourModelHere>): ResponseEntity<yourResponse> {
return ResponseEntity(yourRepository.findAll(Specification.where(specs)), HttpStatus.OK)
}
Use this space to show useful examples of how a project can be used. Additional screenshots, code examples and demos work well in this space. You may also link to more resources.
For more examples, please refer to the Documentation
See the open issues for a list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
Your Name - @sipios_fintech - [email protected]
Project Link: https://github.com/sipios/spring-search