Use of @query annotations for SPRING-DATA-JPA

Source: Internet
Author: User

//------------------------------------using @Query annotations//queries with no parameters@Query ("Select p from person p where p.id = (select Max (p2.id) from person P2)") person Getmaxidperson ();//Use? And the number represents the incoming parameter @query ("Select p from person p where lastname=?1 and email=?2") person Readpersonbylastnameandemail (String lastname,string email);
Use: Represents the incoming parameter @query ("Select p from person p where email=:email and Lastname=:name") Person Readpersonbylastnameandemailthroughname (@Param ("Name") String LastName, @Param ("email") (String email);//use like@Query ("Select p from person p where lastName like? 1") person Readpersonbylike (String likename);//@Query Annotations Support the use of percent sign@Query ("Select p from person p where lastName like%?1%") person ReadPersonByLike2 (String likename);//@Query Annotations Support the use of percent sign@Query ("Select p from person p where lastName like%:lastname%") Person ReadPersonByLike3 (@Param ("LastName") String name);//using native SQL@Query (value= "select * from Jpa_person p1 where p1.last_name like%:lastname%", nativequery=true) Person Getpersonusingoriginsql (@Param ("LastName") String lastName);

Use of @query annotations for SPRING-DATA-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.