小编Joã*_* Fé的帖子

为 SimpleJpaRepository 查找方法指定查询提示

目标

我正在实现一个自定义基础存储库,其目标是能够通过方法参数而不是方法注释来指定实体图的属性节点。因此,不要使用带注释的方法,例如
@EntityGraph(attributePaths = ["enrollments"])
fun findByIdFetchingEnrollments(id: Long): Optional<Student>
Run Code Online (Sandbox Code Playgroud)

在我的存储库中,我只有一个基本存储库,其方法如下

fun findById(id: ID, vararg attributeNodes: String): Optional<T>
Run Code Online (Sandbox Code Playgroud)

这提供了很大的灵活性,因为我只能使用一种方法,例如,调用

studentRepository.findById(1L, "enrollments") 
// or
studentRepository.findById(1L, "favouriteSubjects", "favouriteTeachers")
// and others...
Run Code Online (Sandbox Code Playgroud)

其中"enrollments""favouriteSubjects"、 和"favouriteTeachers"默认情况下是延迟获取实体字段,但有时需要急切地获取(以避免LazyInitializationException

我拥有的

这些是我的课程:
// Base repository interface. All my repositories will extend this interface

@NoRepositoryBean
interface Repository<T, ID> : JpaRepository<T, ID> {

    fun findById(id: ID, vararg attributeNodes: String): Optional<T>
    
    // other find methods

}
Run Code Online (Sandbox Code Playgroud)
// Custom base class. Inherits SimpleJpaRepository

class RepositoryImpl<T, ID>( …
Run Code Online (Sandbox Code Playgroud)

spring spring-data-jpa kotlin

5
推荐指数
0
解决办法
534
查看次数

Common Lisp 中独立于操作系统的路径名

我想加载位于当前工作文件夹子目录中的 lisp 脚本。相对路径是./crossover-operators/ER.lisp

在 Linux 中,这是通过以下方式完成的:

(load "./crossover-operators/ER.lisp")
Run Code Online (Sandbox Code Playgroud)

在 Windows 中是通过以下方式完成的:

(load ".\\crossover-operators\\ER.lisp")
Run Code Online (Sandbox Code Playgroud)

如何创建一个独立于运行 Common Lisp 脚本的操作系统加载ER.lisp脚本的函数?

lisp filesystems common-lisp

3
推荐指数
1
解决办法
150
查看次数