【问题标题】:Meaning of Long in JPARepository?JPARepository中Long的含义?
【发布时间】:2018-08-06 05:30:54
【问题描述】:

这里的Long 是什么,我们在JpaRepository 中配置它的依据是什么?

public interface FirstRepository extends JpaRepository<First, Long> {
}

【问题讨论】:

  • 这与 JPA API 有什么关系(相对于 Spring Data JPA)...
  • 我没有看到long,你的问题是什么?请参阅How to ask a good question

标签: java database spring-boot spring-data-jpa


【解决方案1】:

Long 是主键 (RDBMS) 或自动生成的唯一文档 ID (Mongo DB) 的数据类型。

public interface FirstRepository extends JpaRepository<EntityName,DataType_of_primaryKey> {

}

例如: 如果您的实体是这样的:

class Person{
   Long id;
   String name;
}
public interface FirstRepository extends JpaRepository<Person,Long> {
}

说明

人物 -> 实体

id -> Person 对象的主键(数据类型应为 long

【讨论】:

  • 谢谢。我有这个困惑你解决了。再次感谢
猜你喜欢
  • 2021-12-21
  • 2019-04-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-23
  • 1970-01-01
  • 2016-07-18
相关资源
最近更新 更多