JPQL用法
查询关键字
关键字 | 例子 | SQL 说明 |
---|---|---|
And | findByNameAndAddress | Where s.name = ?1 And s.address = ?2 |
Or | findByNameOrAddress | Where s.name = ?1 Or s.address = ?2 |
Like | findByNameLike | Where s.name like ? 1 |
NotLike | findByNameNotLike | Where s.name not like ?1 |
Between | findByAgeBetween | Where s.age between ?1 and ?2 |
LessThan | findByAgeLessThan | Where s.age < ?1 |
LessThanEqual | findByAgeLessThanEqual | Where s.age <= ?1 |
GreaterThan | findByAgeGreaterThan | Where s.age > ?1 |
GreaterThanEqual | findByAgeGreaterThanEqual | Where s.age >= ?1 |
OrderBy | findSexOrderByAgeDesc | Where s.sex=?1 order by s.age desc |
In | findByAgeIn(Collectionages) | Where s.age in ?1 |
IsNull | findByAgeIsNull | Where s.age is null |
After | findByStartDateAfter | Where s.startDate > ?1 |
Before | findByStartDateBefore | Where s.startDate < ?1 |
除了这些还可以自定义查询
@Query 自定义查询询 ,定制查询 SQL示例:
public interface UserDAO extends Repository<AccountInfo, Long> {
@Query("select a from AccountInfo a where a.accountId = ?1")
public AccountInfo findByAccountId(Long accountId);
@Query("select a from AccountInfo a where a.balance > ?1")
public Page<AccountInfo> findByBalanceGreaterThan(
Integer balance,Pageable pageable);
}
}