第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 Spring boot - H2 數(shù)據(jù)庫中創(chuàng)建外鍵

在 Spring boot - H2 數(shù)據(jù)庫中創(chuàng)建外鍵

長風秋雁 2023-06-14 14:19:09
假設我有兩個簡單的表要在我的Spring Boot應用程序中實現(xiàn)。這是ER圖:這是我的PasswordReset課:@Data@Entitypublic class PasswordReset {@Id @GeneratedValue Long passwordResetID;String eMail;String token;String createdAt;PasswordReset(){}public PasswordReset(String eMail,String token,String createdAt){    this.eMail=eMail;    this.token=token;    this.createdAt=createdAt;}}這是我的User課(部分):@Data   @Entity   public class User {@Id @GeneratedValue Long UserID;String eMail;String createdAt;String updatedAt;User(){}public User(String eMail,String createdAt,String updatedAt){    this.eMail=eMail;    this.createdAt=createdAt;    this.updatedAt=updatedAt;}}現(xiàn)在我的問題是如何在我的Spring Boot項目中創(chuàng)建外鍵,如我的 ER 圖?這是我的pom.xml:<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-starter-parent</artifactId>    <version>2.1.6.RELEASE</version>    <relativePath/> <!-- lookup parent from repository --></parent><groupId>com.mua</groupId><artifactId>cse616</artifactId><version>0.0.1-SNAPSHOT</version><name>cse616</name><description>Project for CSE-616</description><properties>    <java.version>11</java.version></properties><dependencies>    <dependency>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-data-jpa</artifactId>    </dependency>    <dependency>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-web-services</artifactId>    </dependency>
查看完整描述

1 回答

?
尚方寶劍之說

TA貢獻1788條經(jīng)驗 獲得超4個贊

  • mappedBy在父實體(擁有實體)

  • CascadeType.PERSIST,CascadeType.ALL根據(jù)一個請求保存一個孩子和一個父母(你可以根據(jù)需要找到其他的CascadeType)

  • @JoinColumn在我們必須加入的列的子實體

User.java

@OneToMany(mappedBy="user",fetch=FetchType.LAZY,cascade = CascadeType.PERSIST)

private List<ResetPassword> resetpassword = new ArrayList<ResetPassword>();

ResetPassword.java


@ManyToOne(fetch = FetchType.LAZY, targetEntity = User.class)

@JoinColumn(name="userId", referencedColumnName = "userId", nullable = false)

private User user;


查看完整回答
反對 回復 2023-06-14
  • 1 回答
  • 0 關注
  • 220 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號