Spring Data JPA Learning Notes

Source: Internet
Author: User

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

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.