Tags: mysqli unit max Bean program underline OTA habit overApplication.xml file Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:context= "Http://www.springframework.org/schema/context" Xsi:schemalocation= "Http://www.springframework.org/schema/beansHttp://www.springframework.org/schema/beans/spring-beans-4.2.xsdHttp://www.springframework.org/schema/contextHttp://www.springframework.org/schema/context/
Gorky once said--"to use a good spring Data Jpa, you must learn to JPQL."
Hey, heh. Students who have studied hibernate may know that there is a hql in Hibernate, which is independent of the database and can be automatically translated into the SQL of the corresponding database.
JPQL, too, is an object-oriented language that can be ported. Let's go straight ahead
Spring Data JPA provides a number of keywords to express conditional queries for this purpose, roughly as follows:and---are equivalent to the AND keyword in SQL, such as Findbyusernameandpassword (String user, Striang pwd);The or---is equivalent to the OR keyword in SQL, such as findbyusernameoraddress (string user, String addr);The between---is equivalent to the
When Spring data JPA queries the database, if two tables are associated, set a foreign key and create a join query with specification at query time. But only support the left connection, does not support the right connection, although the left and the wrong connection can achieve the same effect, but this is related to who is the foreign key problem. Foreign keys
Usage of @Query annotations (Spring Data JPA) Reference article: http://Www.tuicool.com/articles/jQJBNv 1. A simple example of using @query annotations @query (value="Select Name,author,price from book B where b.price>?1 and b.price") ListLongPrice1,LongPrice2); 2. Like expression @query (value="Select Name,author,pric
rules defined by the Spring Data JPA method: (1) Simple condition querySimple conditional query: Queries an entity class or collection.In accordance with the specifications of Spring data, the query method begins with a Find | read | Get , and when the query condition is in
Hibernate search I will not say more, it is based on Lucene full-text Search tool, remember when the university contacted the Compass full-text Search tool, and then did not use, and then later this guy does not update, So hibernate has launched its own lucene-based full-text Search tool which is the guy hibernate search. Needless to say that the natural advantage is seamless and hibernate integration and even do not need any configuration, has been in the update, recently want to add search fun
(); }5 Complex Interface Jpaspecificationexecutor: Does not inherit the above interface, is a single interface Public Interface Jpaspecificationexecutor { T findOne (specification spec); List spec); Page spec, pageable pageable); List spec, sort sort); Long count (specification spec); } Spring Data
double with a two-bit decimal point behind it.6. @JsonDeserializeThis annotation is used on attributes or setter methods, and can be used to embed our custom code when deserializing, similar to the above @jsonserialize* The JPA namedqueries can be used as follows:1: Use @namedquery on the entity class, as shown in the following example:@NamedQuery (name = "Usermodel.findbyage", query = "Select O from Userm
The spring Data Jpa is used in the project, which is much more comfortable than the hibernate sessionfactory, and most of the SQL statements are automatically generated by spring for us.Previous applications were limited to the basics of spring
With spring Data JPA for more than a year, this is a much more efficient framework that almost removes all boilerplate code
Students who want to learn spring Data JPA are not sure to look at these articles http://www.ibm.com/deve
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
Mysql
Spring Data JPA and native queries with pagination
Spring Data and Native Query with pagination
public interface UserRepository extends JpaRepository
If there is a sort in the Pageable object, sorting can be removed here order by .countQueryc
() + ", Name:" + student.getname () + ", Age:" + student.getage ());}So how to achieve paging? It's simple, as long as the Studentrepository class inherits the PagingAndSorting interface.Public interface Studentrepository extends pagingandsortingrepository{}Operation note the Pageable class needs to introduce the Pageable class in the JPA packageGet CTX = new Classpathxmlapplicationcontext ("Beans-new.xml") according to the context; studentrepository
1. Use of repository objects in the project2.Repository introduced in two waysInheritance and use annotationsDefinition of the 3.Repository interfaceThe Repository interface is a core interface of Spring Data and does not provide any methods, and developers need to declare the required methods in their own defined interfaces.public interface RepositoryT, ID extends Serializable> { } Hierarchical relationshi
//------------------------------------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") Per
(List.size () ==0){ return NULL; } predicate [] predicates=Newpredicate[list.size ()]; //The list is combined with the assertion object in the array predicatespredicates =List.toarray (predicates); //Cb.and equivalent to query conditions using and stitching--and//cb.or equivalent to query conditions using or stitching--or returncb.or (predicates); } }; returnCourierdao.findall (spec, pageable);}StringUtils for org.apache.commons.lang3.StringUtils under the tool cl
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.