Understand the benefits of the Spring Repository Optional<> return type.
- [Instructor] Optional is awesome.…You no longer need to do null checks.…Optional methods combine common data use cases.…So if we would modify the findByName method…in TourPackage repository to return an optional,…then we could have calls such as:…tourPackageRepository.findByName("blah")…and if it's not found, then throw an exception.…If we find it and it isn't found…then we call orElse and create one.…
If we do a findByName and then it is found…and call a get, it'll actually give you the TourPackage.…If it isn't found, be aware that calling get…will throw an exception.…We have an ifPresent on the optional,…so if you look up the findByName("blah")…and if it's present you can actually invoke…a lambda with a value.…And here we actually print out the code of a tour package.…We can call isPresent to returned boolean if it exists…and you can actually chain filters with it as well.…
So in this rudimentary example,…I do a findByName and filter it out…to see if the code of what I'm looking for equals BL.…And if so then if that is present if it finds it…
- Setting up the project
- Building, deploying, and launch the microservice
- Declaring Spring Data JPA repository interfaces
- Invoking repositories
- Using Spring Data query methods
- Exposing RESTful APIs with Spring Data REST
- Using the /search resource to invoke query methods
- Paging and sorting
- Declaring a new REST controller
- Creating HTTP methods for creating, reading, updating and deleting persistent data.