Spring Data JPA Introduction

Source: Internet
Author: User
Tags findone iterable

Spring data is an open-source framework for simplifying database access and supporting cloud services under the SpringSource Foundation. Its main goal is to make database access easy and fast, and to support map-reduce framework and cloud data services. For projects with huge amounts of data, you can use spring data to streamline project development.

However, access is manipulated using a relative class library for different data storage accesses. Spring data has provided us with a number of interfaces and implementation classes commonly used in our business to help us quickly build projects such as paging, sorting, and DAO's common operations.

Core modules

Why does spring data help us build a project quickly, because spring data has already implemented common functionality on the database access layer, and we just need to write an interface that inherits spring data to provide us with access to and operations on the database.

1 Core Interface repository:

 Public Interface extends Serializable> {    }

This interface is simply an empty interface, intended to unify all types of repository, whose interface type uses generics, where T in the generic parameter represents the entity type, and ID is the type of the ID in the entity.

2 Direct sub-interface crudrepository: to provide adding and deleting methods

 Public InterfaceCrudrepository<t, IDextendsSerializable>extendsRepository<t, id> {        <sextendsT>s Save (s entity); <sextendsT> iterable<s> Save (iterable<s>entities);        T FindOne (ID ID); Booleanexists (ID ID); Iterable<T>FindAll (); Iterable<T> FindAll (iterable<id>IDs); Longcount (); voidDelete (ID ID); voidDelete (T entity); voidDelete (iterable<?extendsT>entities); voidDeleteAll (); }

3 Pagination Sort interface pagingandsortingrepository: Sorting and Paging methods

 Public Interface extends extends Crudrepository<t, id> {                iterable<T> findAll (sort sort);                Page<T> findAll (pageable pageable);      }  

4 Jparepository Interface:

  Public InterfaceJparepository<t, IDextendsSerializable>extendsPagingandsortingrepository<t, id>{List<T>FindAll (); List<T>findAll (sort sort); <sextendsT> list<s> Save (iterable<s>entities); voidFlush ();                T Saveandflush (t entity); voidDeleteinbatch (iterable<t>entities); voidDeleteallinbatch (); }

5 Complex Interface Jpaspecificationexecutor: Does not inherit the above interface, is a single interface

 Public Interface Jpaspecificationexecutor<t> {                T findOne (specification<T> spec);                List<T> findAll (specification<t> spec);                Page<T> findAll (specification<t> spec, pageable pageable);                List<T> findAll (specification<t> spec, sort sort);                 Long count (specification<t> spec);      }  

Spring Data JPA Why just define the interface can be used, in fact, it is not difficult to find, look at the source code, you can find an implementation class for Jparepository and Jpaspecificationexecutor, Simplejparepository.class, this class implements the two interfaces just mentioned. And spring is just this simplejparepository.class when we inject the implementation class.

Reference URL:

Http://www.cnblogs.com/simazilin/p/5645947.html

Http://www.cnblogs.com/simazilin/p/5645943.html

Spring Data JPA Introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.