Sample Apps: Spring data MongoDB and JSF Integration tutorial (PART 4)
Spring Data Repository:
Spring Data repository abstraction reduces the boilerplate code to write the data access layer of the application. Automatic implementation of Repository interfaces provides simple operation on mongoDB. It helps our product save and delete function make
MongoTemplate:
MongoTemplate offers convenience operations to create, update, delete and query for MongoDB documents and provides a mapping between your domain objects and MongoDB documents. In our application, since the spring data repository cannot fulfill the requirement of searching function, we use MongoTemplate to archive the searching capability.
Customizing Spring Data Repository
Since the searching of product cannot be easily implement with Spring data repository abstraction, we would like to implements the multi-criteira product search with MongoDBTemplate. To enrich Spring data repository with MongoTemplate, we can do the following to customize the repository:
ProductRepository.java
ProductRepositoryCustom.java
ProductRepositoryImpl.java
Data Model:
Product.java
Pricing.java
Detail.java
JSF Part:
common.xhtml
Search.xhml
ProductSearchCriteria.java
ProductSearchBean.java
Service Layer:
ProductService.java
Source Code:
https://github.com/borislam/spring-data-mongodb-jsf
Originally published at https://www.borislam.com on December 9, 2021.