jackmew / sbJPA

0 stars 0 forks source link

Spring(Boot) Data JPA three type of query. #1

Open jackmew opened 10 years ago

jackmew commented 10 years ago

Spring Data JPA

You can create concrete repositories by creating repository interfaces and letting Spring Data JPA do all the heavy lifting.

Spring Data JPA Tutorial

using Hibernate as your JPA provider

jpaRepository findAll() 回傳的就是List<?>

image

CrudRepository

PagingAndSortingRepository

JpaRepository

Spring Data JPA 三種Query

link

1. Query Creation from Method Name

根據method Name 轉換成相對應的sql query

function名稱 對應方式

2. JPA Named Queries

在Entity上 寫下sql query ,

image

去對應到repository

image

很特別的做法 但感覺一點都不實用

3. @Query Annotation

image

挺正常的做法

我覺得用1 , 3 就很夠用了

接下來做 like 還有 date