Spring Data FrameworkThe extension or use of template scaffolding, which is a secondary development tool. According to this template, you can easily extract the files in the template and develop your own Spring Dataframework.This case is intended for learning and communication and cannot be used for actual production.
Briefly describe how to apply Spring data templates to develop your own Spring Dataframework.
First, you need to create a meaningful project name, which is SpringDatathe name of the current frame. For example, to create a cached SpringDataframe, just name it spring-data-cache. If you want to create a redis’s SpringData, it is named spring-data-redis.
Creating suitable packagethe top pkg, for example, with a spring-data-cacheframe, for example, it packageshould be org.springframework.data.cache, and end is the name of the frame.
PackageAnd implementation class introductionIn general, the top packageHere are the main core of the package to achieve spring-data, which usually are:
Query、Repository、Entity、Configannotation classes for configuration
Query Query annotations, you can configure this annotation in the interface method of repo to complete the custom conditional query.CountQuery Inherit Query to complete count queryModel Entity model annotation, after annotation, you can read the information in the entity annotation to facilitate the persistence operationSetting Entity model annotations, such as the configuration path of the current entityField Entity model attribute annotation, you can map attributesScore Entity attribute annotation, attribute additional configuration informationconfig: configuration type, based onSpringDatathe configuration base class, Entity scan class, etc.
AbstractTemplateConfiguration The template configuration base class, some common configuration information can be preferentially configured in itTemplateEntityClassScannerScanning Repositoryused EntityClass, in AbstractTemplateConfiguration.getInitialEntitySetdependence of the type of processTemplateNamespaceHandler Configuration injection of namespaces, you don’t needcore : Core business is done repository to achieve the underlying business CRUD operations
converter: underlying interface entity and repository interaction time, object-type field converter
DateTimeConverter Date time and string conversion, there can also be conversion implementations of other classesMappingTemplateConverter Map converter to complete the mapping between the underlying and the entityTemplateConverter Map converter interface definitionmapping: mapping between entities and underlying interface objects, field types
TemplatePersistentEntity Persistent entity object interface, you can define additional information necessary for a number of persistent entities, to facilitate the realization of repositorythe use of timeTemplatePersistentProperty Persistent entity object attribute interface, additional necessary information to define persistent attributesSimpleTemplateMappingContext Mapping context, providing methods for building persistent entities and attributesSimpleTemplatePersistentEntity Persistent entity object interface implementationSimpleTemplatePersistentProperty Persistent entity object attribute interface implementationquery : query string, annotation inquiry, CRUD operation conditions of the core implementation
MyTplTemplateTemplate class, CRUD operations is completed, provided to the repositoryunderlying implementation
TemplateOperations Template class interface, complete the definition of CRUD operations
enums : enum class configuration
repository: repository interface rules and main implementation
cdi: CDI implemented using dependency injection, without depending on spring the case of injection, the injection may be used
TemplateRepositoryBeanUse CdiRepositoryBean Creating Repositoryobject instancesTemplateRepositoryExtensionA portable CDI extensions, it is Repositoryregistered bean, provided CdiRepositoryBeanto achieve the requiredconfig: based onSpringData the configuration class, open the current framework or some basic configuration
EnableTemplateRepositoriesCore configuration, whether open spring-data-templateframework and loaded configurationTemplateRepositoriesRegistrarSet RepositoriesRegistrarregistration implementationTemplateRepositoryConfigurationExtensionProvide RepositoryConfigurationconfiguration information to achievequery: Based on SpringData the query implementation, basic needs SpringCommon some interfaces and classes to complete
repositoryinterface annotation SQL string query and PartTreequeryrepositoryinterface annotation SQL string queries and PartTreequeriesTemplateQueryMethodProvide repositorybasic information about the interface query methodSimpleTemplateQueryCreatorrepositoryDynamically generate SQL query statements through interface query methodsTemplateEntityMetadataProvide repositorymetadata information for persistent entity objectssupport: current repository core implementation
TemplateEntityInformationExpand EntityMetadatato add the ability to query entity instance informationMappingTemplateEntityInformationImplement EntityInformation to populate Entity related information. And you can take advantage of Converter/PersistentEntitydata conversion and the filling.TemplateEntityInformationCreatorEntity information TemplateEntityInformationObject creator InterfaceTemplateEntityInformationCreatorImplEntity information TemplateEntityInformationObject creator interfaceTemplateRepositoryFactoryBy TemplateRepositoryFactoryCreating TemplateRepositoryinstancesTemplateRepositoryFactoryBeanCore class, create an TemplateRepositoryFactoryinstanceAbstractTemplateRepository Abstract implementation of repo , easy to expandSimpleTemplateRepositorySimple implementation TemplateRepository, supporting entity and string generics, string type IdNumberKeyedRepositorySimple implementation TemplateRepository, Numbertype IdUUIDTemplateRepositorySimple implementation TemplateRepository, UUIDtype IdTemplateRepositoryTop repositoryinterfaces, all interfaces inherit the completion CRUDof repothe operation
corerelated to other related businessespackageSpringDataAnd can SpringBoot、SpringCloud、SpringFrameworkseamlessly integrate, develop their own SpringDataframework for ease of use and expand the system. This framework is just a template to help you understand and learn the underlying interface knowledge of SpringData.