【问题标题】:Why in jpaRepository is used Long?为什么在 jpaRepository 中使用 Long?
【发布时间】:2021-12-21 10:53:58
【问题描述】:

我是 Spring Boot 和 JpaRepository 的新手。我想知道为什么使用 Long 而不是其他数据类型?

【问题讨论】:

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


    【解决方案1】:

    无需使用Long,您可以使用StringUUID 等任何类型或自定义类型。

    例如所有这些都是可能的:

    public interface UserRepository extends CrudRepository<User, Long>
    
    public interface UserRepository extends CrudRepository<User, String>
    
    public interface UserRepository extends CrudRepository<User, UUID>
    
    public interface UserRepository extends CrudRepository<User, UserId>
    

    重要的是它指的是您用作实体主键的任何内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-28
      • 1970-01-01
      • 1970-01-01
      • 2021-01-13
      • 1970-01-01
      • 2020-08-20
      • 2020-11-11
      • 2011-08-17
      相关资源
      最近更新 更多