Udemy Course Spring Framework 49-Spring Data JPA(比較另一table資料)
延續47的練習
執行SpringDataDemoApplication.java
實際是使用PersonSpringDataRepository
其中是延續使用Spring JPA定義在JpaRepository的方法
findById(由PK找資料)
save(INSERT)
save(UPDATE)
deleteById(由PK刪資料)
findAll(找全部資料)
而資料由Spring JPA產生
所以data.sql剩
現在自己研究額外內容:
現在再多給一個Entity →IdCard
註:這邊要餵@Table指定名稱idcard
不然class名IdCard會產生出Id_Card的table
然後data.sql只餵資料:
在介面PersonSpringDataRepository加入兩行自製Query:
由上可以看到,我只是把person table有的資料跟idcard比對一下
目前基本是person跟idcard透過id是1對1關係
由data.sql加入的內容 我們應可得到id為10001與10003的person資料
再SpringDataDemoApplication.java
呼叫新增的這個query Method
執行得:
藍框是person現有的全部資料
而紅框是person跟idcard比對後有符合的資料!!!