
上QQ阅读APP看书,第一时间看更新
2.2 Repository的类层次关系
(diagms/hierarchy/structure)
我们来根据Repository这个基类顺藤摸瓜,看看Spring Data JPA里面都有些什么,顺便教大家学习的方法,这样不管碰到什么框架,学习方法都类似,自己可以逐步从入门到精通,提高学习效率。
(1)我们用工具IntelliJ IDEA,打开类Repository.class,单击Navigate→Type Hierarchy。然后我们会得到如图2-2所示的视图。

图2-2
通过这个层次结构视图,我们就会明白基类Repository的实现,对工程里面的所有Repository了如指掌,我们项目里面有哪些、Spring的项目里面有哪些也会一目了然。
(2)通过IntelliJ IDEA打开类Example1里面的UserRepository.java,右击选择show diagrams,用图表的方式查看类的层次关系,如图2-3所示。

图2-3
(3)通过IntelliJ IDEA打开类QueryDslJpaRepository,右击,选择show diagrams,用图表的方式查看类的关系层次。打开的界面如图2-4所示。

图2-4
(4)通过IntelliJ IDEA打开类Example1里面的UserRepository.java,打开Navigate→File Structure,可以查看此类的结构以及有哪些方法。以此类推到其他类上。打开的界面如图2-5所示。

图2-5
以上三种视图是开发过程中经常用到的视图。
我们来看一个Repository的实例:
