Spring Data:Repository类

博客介绍了Repository类的定义,它是一个空的标记接口,若自定义接口不继承它运行时会报错,添加特定注解可实现相同功能。同时指出继承Repository后,方法名不能随意定义,需采用固定格式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Repository类的定义:

public interface Repository<T, ID extends Serializable> {}

1)Repository是一个空接口,标记接口
没有包含方法声明的接口

2)如果我们自己的接口没有extends Repository,运行时会报错:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No
qualifying bean of type ‘com.imooc.repository.EmployeeRepository’
available

  1. 添加注解能到达到不用extends Repository的功能
    @RepositoryDefinition(domainClass = Employee.class, idClass = Integer.class)
继承Repository后方法名定义

继承Repository后方法名不能随便定义,需要使用固定格式

KeywordSampleJPQL snippet
AndfindByLastnameAndFirstname…where x.lastname=? and x.firstname=?
OrfindByLastnameOrFirstname…where x.lastname=? or x.firstname=?
BetweenfindByStartDateBetween…where x.startDate between ? and ?
LessThanfindByAgeLessThan…where x.age<?
GreaterThanfindByAgeGreaterThan…where x.age>?
AfterfindByStartDateAfter…where x.startDate>?
BeforefindByStartDateBefore…where x.startDate<?
isNullfindByAgeIsNull…where x.age is null
isNotNull,NotNullfindByAge(Is)NotNull…where x.age not null
LikefindByFirstnameLike…where x.firstname like ?
NotLikefindByFirstnameNotLike…where x.firstname not like ?
StartingWithfindByFirstnameStartingWith…where x.firstname like ?(参数后加%)
EndingWithfindByFirstnameEndingWith…where x.firstname like ?(参数前加%)
ContainingfindByFirstnameContaining…where x.firstname like ?(参数前后都加%)
OrderByfindByAgeOrderByLastnameDesc…where x.age=? order by x.lastname desc
NotfindByLastnameNot…where x.lastname <> ?
InfindByAgeIn…where x.age in ?
NotInfindByAgeNotIn…where x.age not in ?
TRUEfindByActiveTrue…where x.active=true
FALSEfindByActiveFalse…where x.active=false
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值