【发布时间】:2018-11-18 11:59:36
【问题描述】:
我正在为我的项目使用 spring data jpa,并且我有以下代码:
我的仓库:
@Repository
@Transactional
public interface StudentRepository extends PagingAndSortingRepository<Student, Long> {
List<Student> findByIdIn(List<Long> ids);
}
我的实体是:
@Entity
public class Student implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
// other fields
// getters/setters
}
在我的服务类的某个地方,我有
@Autowired
StudentRepository studentRepository;
然后我从我的服务层调用 findByIdIn,例如:
studentRepository.findByIdIn(listOfIds);
findByIdIn(listOfIds) 方法工作得很好,一切都按预期工作。
我知道findByIdIn()方法的实现是spring data jpa提供的。
但我不知道它的实现在哪里? 它的具体实现是什么? 这些方法是否在运行时生成取决于方法名称?如果是,它们是如何动态生成和执行的?
谢谢!
【问题讨论】:
-
请浏览这篇文章。这可能会有所帮助:) stackoverflow.com/questions/38509882/…
-
这篇文章很好地解释了当我们用@Query注释我们的附加方法时的流程。但在这种情况下,我没有用 @Query 注释我的方法。
标签: java spring hibernate spring-data-jpa spring-data