Repository类的定义

Repository类的定义:
public interface Repository<T, ID extends Serializable> {


}


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


2)如果我们定义的接口EmployeeRepository extends Repository


如果我们自己的接口没有extends Repository,运行时会报错:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.imooc.repository.EmployeeRepository' available


3) 添加注解能到达到不用extends Repository的功能
@RepositoryDefinition(domainClass = Employee.class, idClass = Integer.class)






insert into employee (name, age) values ("test1",20);
insert into employee (name, age) values ("test2",21);
insert into employee (name, age) values ("test3",22);
insert into employee (name, age) values ("test4",20);
insert into employee (name, age) values ("test5",21);
insert into employee (name, age) values ("test6",22);
insert into employee (name, age) values ("test16",22);


//"test",22
id:2 , name:test1 ,age:20
id:3 , name:test2 ,age:21
id:5 , name:test4 ,age:20
id:6 , name:test5 ,age:21


对于按照方法命名规则来使用的话,有弊端:
1)方法名会比较长: 约定大于配置
2)对于一些复杂的查询,是很难实现




@Query




事务在Spring data中的使用:
1)事务一般是在Service层
2)@Query、 @Modifying、@Transactional的综合使用









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值