zoukankan      html  css  js  c++  java
  • SpringDataJPA(ORM对象关系映射框架)

    1. JPA,SpringDataJPA,hibernate的关系

    a)       JPA仅仅是一种规范(相当于我们平时说的接口),而hibernate是JPA的一个实现,而SpringDataJPA就是对JPA的进一步封装

    1. 数据的操作

    a)       批量查询时,定义一个List,list里面传入要查询个数等。

    b)       分页加排序的时候,先获取到排序对象,然后获取分页对象,将排序对象传到分页对象里面,然后将分页对象传到查询语句中

    1. Spring集成SpringDataJPA

    a)       导包(一定要导入SpringDataJPA的两个核心包jpa-spec,spring-data-jpa)

    b)       配置ApplicationContext.xml文件

    c)        完成repository的功能

                         i.            自定义的Repository接口去继承JpaRepository接口,就包含了许多操作数据库的方法,

                       ii.            Spring Data JPA的七个Repository接口:

    Repository(org.springframework.data.repository.Repository)
    CrudRepository(org.springframework.data.repository.CrudRepository)
    PagingAndSortingRepository(org.springframework.data.repository.PagingAndSortingRepository)
    JpaRepository (org.springframework.data.jpa.repository.JpaRepository)
    QueryByExampleExecutor(org.springframework.data.repository.query.QueryByExampleExecutor)
    JpaSpecificationExecutor (org.springframework.data.jpa.repository.JpaSpecificationExecutor)
    QueryDslPredicateExecutor (org.springframework.data.querydsl.QueryDslPredicateExecutor)
     
    两大Repository实现类:
    SimpleJpaRepository(org.springframework.data.jpa.repository.support.SimpleJpaRepository)
    QueryDslJpaRepository(org.springframework.data.jpa.repository.support.QueryDslJpaRepository)

                      iii.            @Query注解查询

    1. 将@Query注解打到repository方法上面即可

                      iv.            JpaSpecification[Office1] Executor[Office2] 

    1. 这个接口的方法全都要传入一个Specification[Office3] 对象
    2. Query查询条件的抽取

    a)       BaseQuery的抽取

                                                            i.            抽取出排序的方法和获取Specification[Office4] 的一个抽象方法

                                                          ii.            DomainQuery继承BaseQuery赋写Specification[Office5] 的方法,添加查询的条件。

  • 相关阅读:
    LODOP中用ADD_PRINT_IMAGE缩放非图片超文本
    LODOP关联,打印项序号注意事项
    LODOP在页面让客户选择打印机
    【JS新手教程】LODOP打印复选框选中的任务或页数
    映美FP-530K+打印发票的各种经验
    【JS新手教程】LODOP打印复选框选中的内容
    LODOP和C-LODOP注册与角色等简短问答【增强版】
    【JS新手教程】弹出两层div,及在LODOP内嵌上层
    LODOP内嵌挡住浏览器的div弹出层
    【JS新手教程】浏览器弹出div层1
  • 原文地址:https://www.cnblogs.com/8888-lhb/p/11291886.html
Copyright © 2011-2022 走看看