Spring data implements a custom repository implementation class that implements the JPA

Source: Internet
Author: User

If you do not want to expose so many methods, you can customize their own repository, but also in their own repository to add their own public methods of course more flexible is to write an implementation class to achieve their own Method 1: Write a class with the same name as the interface, The suffix is impl, which is configured in the previous XML and can be scanned automatically. This class does not need to implement any interfaces. 2: In the interface to add their own methods, such as: Public page<object[]> getbycondition (Userquerymodel u); 3: In the implementation class, to implement this method is good, will be automatically found
Java code:
    @PersistenceContext      private Entitymanager em;         Public page<object[]> getbycondition (Userquerymodel u) {  String hql = ' Select O.uuid,o.name from Usermodel o whe Re 1=1 and O.uuid=:uuid ";          Query q = em.createquery (HQL);          Q.setparameter ("UUID", U.getuuid ());                  Q.setfirstresult (0);          Q.setmaxresults (1);       page<object[]> page = new pageimpl<object[]> (Q.getresultlist (), New Pagerequest (0,1), 3);           return page;  }}  

Spring data implements a custom repository implementation class that implements the JPA

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.