Spring Data:Repository类

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
【2021年,将Spring全家桶系列课程进行Review,修复顺序等错误。进入2022年,将Spring的课程进行整理,整理为案例精讲的系列课程,并新增高级的Spring Security等内容,通过手把手一步步教你从零开始学会应用Spring,课件将逐步进行上传,敬请期待】 本课程是Spring案例精讲课程的第五部分Spring DataSpring案例精讲课程以真实场景、项目实战为导向,循序渐进,深入浅出的讲解Java网络编程,助力您在技术工作中更进一步。 本课程聚焦Spring Data的核心知识点:Spring Data RepositorySpring Data JPA(增删改查案例、实体自动生成数据库表、增加新的Repository方法、分页、排序、@NamedQuery、@Query及其分页和排序及参数设置、@NamedEntityGragh实现多对多映射、及QueryHints等)、Spring Data JDBC(增删改查案例、@Query等)的案例介绍, 快速掌握Spring Data的核心知识,快速上手,为学习及工作做好充足的准备。 由于本课程聚焦于案例,即直接上手操作,对于Spring的原理等不会做过多介绍,希望了解原理等内容的需要通过其他视频或者书籍去了解,建议按照该案例课程一步步做下来,之后再去进一步回顾原理,这样能够促进大家对原理有更好的理解。 【通过Spring全家桶,我们保证你能收获到以下几点】 1、掌握Spring全家桶主要部分的开发、实现2、可以使用Spring MVC、Spring Boot、Spring Cloud及Spring Data进行大部分的Spring开发3、初步了解使用微服务、了解使用Spring进行微服务的设计实现4、奠定扎实的Spring技术,具备了一定的独立开发的能力  【实力讲师】 毕业于清华大学软件学院软件工程专业,曾在Accenture、IBM等知名外企任管理及架构职位,近15年的JavaEE经验,近8年的Spring经验,一直致力于架构、设计、开发及管理工作,在电商、零售、制造业等有丰富的项目实施经验  【本课程适用人群】如果你是一定不要错过!  适合于有JavaEE基础的,如:JSP、JSTL、Java基础等的学习者没有基础的学习者跟着课程可以学习,但是需要补充相关基础知识后,才能很好的参与到相关的工作中。 【Spring全家桶课程共包含如下几门】5. 进阶篇:SpringData 

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值