gpt4 book ai didi

java - ORM如何映射到接口(interface)?

转载 作者:行者123 更新时间:2023-12-02 01:51:44 25 4
gpt4 key购买 nike

这些天我正在学习 JPA Projections!
有一些奇怪的事情我无法理解。

以下是我的问题

Spring Data JPA 存储库

public interface PersonRepository extends JpaRepository<Person, Serializable> {

Collection<NameAgeOnly> findByAgeGreaterThan(int age);
}

接口(interface)(没有Clazz实现该接口(interface))

public interface NameAgeOnly {
String getName();

String getAge();
}

存储库测试

public class RepositoryTest {
List<CountByAddress> countByAddressList = personRepository.getCityNameAndPersonCount();
debug.log(countByAddressList.get(0).getName());
}

countByAddressList.get(0).getName 如何工作?没有实现NameAgeOnly的类吗?

接口(interface)有默认类吗?谁能解释一下如何将 ORM 映射到接口(interface)而不是类?

谢谢:)

最佳答案

The documentation解释一下:

The query execution engine creates proxy instances of that interface at runtime for each element returned and forwards calls to the exposed methods to the target object.

关于java - ORM如何映射到接口(interface)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52904876/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com