JPA介面查詢

2021-08-11 14:13:40 字數 2275 閱讀 8400

本人首次玩,有不對的地方請見諒,不喜勿噴,謝謝.

有時可以看到在dao裡面的介面方法,有些是沒有用註解寫sql語句也沒有在配置檔案寫sql語句的,而只是有個光禿禿的介面名,但是它既然還可以查詢到資料庫裡的資料.因為這是用到了jpa,介面名遵循jpa方法命名規則,通過介面名就可以解析成sql語句,然後查到資料.

如有需要可以找度娘先了解下jpa

接下來本人通過下面的介面類來講解下:

public inte***ce studentdao extends jparepository>

下面根據**依次列出方法名表明的意思,如有不對請指出,勿噴,謝謝.

方法名關鍵字

sqlfindbyid

where id=?

findbyidis

iswhere id=?

findbyidequals

equals

where id=?

findbynameandage

andwhere name=? and age=?

findbynameorage

orwhere name=? or age=?

findbynameorderbyagedesc

order by

where name=? order by age desc

findbyagenotin

not in

where age not in(?)

findbystatustrue

true

where status=true

findbystatusfalse

false

where status=false

findbyagebetween

between

where age between ? and ?

findbynamenot

notwhere name <> ?

findbyagelessthan

lessthan

where age< ?

findbyagelessthanequal

lessthanequal

where age<=?

findbyagegreaterthan

greaterthan

where age>?

findbyagegreaterthanequal

greaterthanequal

where age>=?

findbyageafter

after

where age>?

findbyagebefore

before

where age< ?

findbynameisnull

is null

where name is null

findbynamenotnull

not null

where name not null

findbynamelike

like

where name like ?

findbynamenotlike

not like

where name not like ?

findbynamestartingwith

startingwith

where name like 『?%』

findbynameendingwith

endingwith

where name like 『%?』

findbynamecontaining

containing

where name like 『%?%』

**中幾個複雜的.

findbynameandageand***:表示where name=? and age=? and ***=?

findbynameinandageisnull :表示where name in (?) and age is null

findbynameandageinand***in:表示where name=? and age in(?) and *** in(?)

可以看出關鍵字是可以連用的,查詢都是用findby+表中列名,表的列名還有關鍵字等等拼接時,它們的首字母要大寫.

本次就暫時寫到這,如有不對請見諒,在錯誤中成長.

JPA註解查詢

1 entity name entityname 必須,name為可選,對應資料庫中一的個表 entity 標識這個pojo是乙個jpa實體 public class users implements serializable 2 table name catalog schema 可選,通常和 e...

Jpa多表查詢

作業題目 api 商品列表 get sell buyer product list引數無 返回 建立訂單 post sell buyer order create 引數返回 訂單列表 get sell buyer order list 引數openid 18eu2jwk2kse3r42e2e pag...

jpa關聯查詢

栗子1 以乙個實體類user中的幾個屬性進行篩選。1.名字 2.id 3.手機號這是乙個單錶的多條件複雜查詢,由於是在幾個屬性中進行篩選,其中的屬性的個數不知道有多少個,所以只需要利用specification 查詢就可以很方便的實現這個需求。下面請看 場景 頁面上通過條件篩選,查詢使用者列表 這裡...