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进行复杂对象查询
参考文档:
网友评论