Querydsl

Querydsl是一个Java开源框架用于构建类型安全的SQL查询语句。它采用API代替拼凑字符串来构造查询语句。可跟 Hibernate 和 JPA 等框架结合使用。

基本查询:

?
1
2
3
4
5
6
JPAQuery query =  new  JPAQuery(entityManager);
List<Person> persons = query.from(person)
   .where(
     person.firstName.eq( "John" ),
     person.lastName.eq( "Doe" ))
   .list(person);

子查询:

?
1
2
3
4
5
List<Person> persons = query.from(person)
   .where(person.children.size().eq(
     new  JPASubQuery().from(parent)
         .uniqueResult(parent.children.size().max())
   )).list(person);

排序:

?
1
2
3
4
List<Person> persons = query.from(person)
   .orderBy(person.lastName.asc(), 
            person.firstName.desc())
   .list(person);
 
 
http://www.oschina.net/search?scope=project&q=Querydsl
 
https://github.com/querydsl/querydsl
http://www.querydsl.com/

猜你喜欢

转载自m635674608.iteye.com/blog/2233935