【问题标题】:How to fetch Record from postgresql or MySQL table in spring boot using foreign key JpaRepository FindByAddress() without jpa query如何在没有jpa查询的情况下使用外键JpaRepository FindByAddress()在spring boot中从postgresql或MySQL表中获取记录
【发布时间】:2021-06-19 07:17:16
【问题描述】:

@ManyToOne() @JoinColumn(name = "address", referencedColumnName = "id", 可更新 = true)

私有StudentModel地址= null;

【问题讨论】:

    标签: spring-boot spring-data-jpa


    【解决方案1】:

    你可以这样做,最好的解决方案,但唯一的地址,或者你可以将地址替换为 userId

    @ManyToOne() @JoinColumn(name = "address", referencedColumnName = "id", insertable = false, updatable = true)

    private StudentModel studentAddress= null;
    

    @Column(name = "address", updateable = false, nullable = false, length = 60, unique = true)

    私有字符串地址;

    FindByAddress("地址名");

    如果是地址列表则 FindAllByAddress("anyaddressname");

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-26
      • 2018-10-30
      • 1970-01-01
      • 2018-11-26
      • 1970-01-01
      • 2018-07-12
      相关资源
      最近更新 更多