Spring data is an open-source framework for simplifying database access and supporting cloud services, with the primary goal of making access to data easy and fast. Access to and manipulation of data can be achieved with virtually no write implementation. In addition to CRUD, it also includes some common functions such as paging, sorting, and so on.
Interface provided by Spring Data JPA:
1:repository: The topmost interface, which is an empty interface, is designed to unify all types of Repository and to automatically recognize components as they are scanned.
2:crudrepository: is a repository sub-interface that provides CRUD functionality.
3:pagingandsortingrepository: is a crudrepository sub-interface that adds paging and sorting functionality.
4:jparepository: Is the Pagingandsortingrepository sub-interface, added some useful functions, such as: batch operation.
5:jpaspecificationexecutor: Used to do the interface responsible for querying.
6:specification: is a query specification provided by Spring Data JPA, to make complex queries, just set the query criteria around this specification.
Example:
Public interface Userrepository extends Jparepository<usermodel, long>{}
Page<usermodel> p = ur.findall (new Pagerequest (0,2,new Sort (Direction. DESC, "uuid")));
Page<usermodel> Findbyname (String name, pageable pageable);
List<usermodel> Findbyname (String name, sort sort);
@Query (value= "Select O from Usermodel o where o.name like%:nn")
Public list<usermodel> Findbyuuidorage (@Param ("nn") String name);
[Note: 1: The return value of the method should be int, indicating the number of rows affected by the UPDATE statement; 2: A transaction must be added where it is called, no transaction cannot be performed properly]
@Modifying
@Transaction
@Query (value= "Update Usermodel o set o.name=:newname where o.name like%:nn")
public int Findbyuuidorage (@Param ("nn") string name, @Param ("NewName") string newName);
Resource address: http://si sh uo k.com/forum/blogpost/list/7000.html
Spring Data JPA Learning Notes