JPA中自定義查詢語句

2021-08-30 17:45:36 字數 2573 閱讀 5029

>

>

org.springframework.bootgroupid

>

>

spring-boot-starter-parentartifactid

>

>

2.0.4.releaseversion

>

>

relativepath

>

parent

>

......

實體類

@entity

@table

(name =

"sensitive"

)@apimodel

(value =

"詞彙資訊"

)public

class

sensitive

dao介面

@repository

@transactional

public

inte***ce

sensitivedao

extends

jparepository

, jpaspecificationexecutor

簡單使用

@lazy

@service

public

class

sensitiveservice

catch

(exception e)

return

newresult

<

>

(resultstatus.error_select_out);}

....

..}

dao介面

@repository

@transactional

public

inte***ce

sensitivedao

extends

jparepository

, jpaspecificationexecutor

簡單使用

...

...public result

>

selectsensitive

(string word)

catch

(exception e)

return

newresult

<

>

(resultstatus.error_select_out);}

....

..

dao介面

// 拼接sql在service層實現
簡單使用

...

.../**

* 詞彙查詢.

* @param type [選]詞彙型別(精確)

* @param word [選]詞彙(模糊)

* @param start [選]開始時間戳(毫秒級)

* @param end [選]結束時間戳(毫秒級)

* @param page [選必]當前頁位置,從0計數

* @param size [選]當前每頁大小

* @return

*/public result

>

selectsensitive

(string type, string word, long start, long end, integer page, integer size)

else

// list.add(p);}}

*/predicate[

] p =

newpredicate

[list.

size()

];return cb.

and(list.

toarray

(p));}

}, org.springframework.data.domain.pagerequest.

of(page, size));

return

0== result.

gettotalelements()

?new

result

<

>

(resultstatus.null_select)

:new

result

<

>

(resultstatus.success_select, page, size, result.

gettotalelements()

, result.

getcontent()

);}catch

(exception e)

return

newresult

<

>

(resultstatus.error_select_out);}

....

..

自定義查詢

自定義查詢是一種比較常用的功能。功能劃分為兩部分。一是系統管理員根據需求訂製出查詢需要使用到的一些有關聯的表的集合,作為查詢的基礎模型 二是使用者可以在這個模型的基礎上定義自己的查詢條件,包括定義查詢的輸出顯示項,來實現靈活的查詢功能。用例圖如下所示 系統的功能結構圖如下所示,包括兩大功能,分別是模...

thinkjs中自定義sql語句

一直以為在使用thinkjs時,只能是它自帶的sql語句查詢,當遇到類似於這樣的sql語句時,卻不知道這該怎樣來寫程式,殊不知原來thinkjs可以執行自定義sql語句 select from adinfo where 1481286720 between stime and etime or 14...

spring data jpa 自定義查詢

spring data jpa 內部封裝了引用了 hibernate 的介面。使用時,實際上使用的是 hibernate 的相關方法,自定義查詢也是按照 hibernate 進行的 整合 jpa 的介面 public inte ce teacherrepository extends jparepo...