-
spring-data是spring提供的数据访问层框架,封装若干种数据服务访问能力。
spring-data-jpa:通过JPA标准规范,底层使用Hibernate框架实现。 spring-data-jdbc:就是底层使用spring-jdbc实现,可以使用Mybatis技术作为底层实现的替代产品。 spring-data-redis:底层使用jedis实现。
-
spring-data-JPA
- 类图
- Repository标记接口。可以继承此接口,根据指定的规则,实现数据查询。只能做单表查询,且查询结果一定是实体类型对象或实体类型对象的集合。命名规则:findBy(关键字)+属性名称(属性名称的首字母大写)+查询条件(首字母大写)
关键字
方法命名
sql where字句
And
findByNameAndPwd
where name= ? and pwd =?
Or
findByNameOrSex
where name= ? or sex=?
Is,Equal
findById,findByIdEquals
where id= ?
Between
findByIdBetween
where id between ? and ?
LessThan
findByIdLessThan
where id < ?
LessThanEqual
findByIdLessThanEquals
where id <= ?
GreaterThan
findByIdGreaterThan
where id > ?
GreaterThanEqual
findByIdGreaterThanEquals
where id > = ?
After
findByIdAfter
where id > ?
Before
findByIdBefore
where id < ?
IsNull
findByNameIsNull
where name is null
isNotNull,NotNull
findByNameNotNull
where name is not null
Like
findByNameLike
where name like ?
NotLike
findByNameNotLike
where name not like ?
StartingWith
findByNameStartingWith
where name like '?%'
EndingWith
findByNameEndingWith
where name like '%?'
Containing
findByNameContaining
where name like '%?%'
OrderBy
findByIdOrderByXDesc
where id=? order by x desc
Not
findByNameNot
where name <> ?
In
findByIdIn(Collection<?> c)
where id in (?)
NotIn
findByIdNotIn(Collection<?> c)
where id not in (?)
True
findByAaaTue
where aaa = true
False
findByAaaFalse
where aaa = false
IgnoreCase
findByNameIgnoreCase
where UPPER(name)=UPPER(?)
- 类图