美文网首页Java
Spring Data JPA 基本使用

Spring Data JPA 基本使用

作者: 丿星纟彖彳亍 | 来源:发表于2021-03-19 09:34 被阅读0次

    JPA查询传递参数和对象

    参数

    // 布尔值得加引号
    // 取参格式 :pram 和 ?序号
    @Query(value = "select ksmc as name,ksdm as departmentId, 'false' as hasChildren, 0 as remain from Gy_ksdm where ksdm = :parentId and contains (ksmc, :keyWord) > 0", nativeQuery = true)
    List<QueryDepartmentListResponseData> findAllByNameAndKsdm (@Param("parentId") String parentId, @Param("keyWord") String keyWord);
    
    @Query(value = "select ksmc as name,ksdm as departmentId, 'false' as hasChildren, 0 as remain from Gy_ksdm where ksdm = ?1 and contains (ksmc, ?2) > 0", nativeQuery = true)
    List<QueryDepartmentListResponseData> findAllByNameAndKsdm (String parentId,  String keyWord);
    

    对象

    // 取参格式 :#{#class.field}
    @Query(value = "select ksmc as name,ksdm as departmentId, 'false' as hasChildren, 0 as remain from Gy_ksdm where ksdm = :#{#depart.parentId} and contains (ksmc, :#{#depart.keyWord}) > 0", nativeQuery = true)
    List<QueryDepartmentListResponseData> findAllByNameAndKsdm (@Param("depart") QueryDepartmentListRequest depart);
    

    通过spring-data-jpa进行复杂对象查询

    通过spring-data-jpa进行复杂对象查询

    参考文档:

    相关文章

      网友评论

        本文标题:Spring Data JPA 基本使用

        本文链接:https://www.haomeiwen.com/subject/ujungktx.html