Spring?Data?Jpa?中原生查詢?REGEXP?的使用詳解
Spring Data Jpa原生查詢 REGEXP 的使用
REGEXP 與like 有通用之處, 單 regexp 有更好的精確度,更加自由靈活
在jpa 中使用時(shí) :其中 定位符 ^ 在jpa @query 注解中使用時(shí)需要加上引用號(hào) e.g
@Query(value = "select p.id as id from zt_products AS p where p.enabled=true and p.name regexp '^'+?1+'$' ", nativeQuery = true) List<Map> findByName(String names);
如此 方可使用,,但是% 可以不用加。。。。
嗯 暫時(shí)就這個(gè)樣子///
后記:
在實(shí)際使用時(shí) 發(fā)現(xiàn)上述方法存在缺陷; 無論names傳的什么值 查詢結(jié)果一樣;
@Query(value = "select p.id as id from zt_products AS p where p.enabled=true and p.name regexp ?1, nativeQuery = true) List<Map> findByName(String rexgexp);//rexgexp 為 regexp 表達(dá)式 直接在這里和一起會(huì)不起作用
可參考:
https://spring.io/blog/2014/07/15/spel-support-in-spring-data-jpa-query-definitions
https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.stored-procedures
spring data jpa 原生查詢(查一個(gè)json中的某一字段)
數(shù)據(jù)庫:
jpa 查詢 java:
@Component("ediHistoryDAO") public interface EdiHistoryDAO extends CrudRepository<EdiHistoryDO, Integer>{ EdiHistoryDO findById(BigInteger id); EdiHistoryDO findByEdiInfoId(BigInteger id); List<EdiHistoryDO> findByIdIn(List<BigInteger> id); @Query(value="select * from EDI.edi_history where json_contains(response_summary, ?1) and json_contains(response_summary, ?2) and json_contains(response_summary, ?3) and json_contains(response_summary, ?4)", nativeQuery = true) public List<EdiHistoryDO> findByResponseSummary(String result,String orderNo,String orderId,String docType); }
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
java連接mysql數(shù)據(jù)庫實(shí)現(xiàn)單條插入和批量插入
這篇文章主要為大家詳細(xì)介紹了java連接mysql數(shù)據(jù)庫實(shí)現(xiàn)單條插入和批量插入,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-08-08Java利用位運(yùn)算實(shí)現(xiàn)比較兩個(gè)數(shù)的大小
這篇文章主要為大家介紹了,在Java中如何不用任何比較判斷符(>,==,<),返回兩個(gè)數(shù)( 32 位整數(shù))中較大的數(shù),感興趣的可以了解一下2022-08-08springboot多個(gè)service互相調(diào)用的事務(wù)處理方式
這篇文章主要介紹了springboot多個(gè)service互相調(diào)用的事務(wù)處理方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-02-02Spring?Boot?整合持久層之Spring Data JPA
在介紹Spring Data JPA的時(shí)候,我們首先認(rèn)識(shí)下Hibernate。Hibernate是數(shù)據(jù)訪問解決技術(shù)的絕對(duì)霸主,使用O/R映射技術(shù)實(shí)現(xiàn)數(shù)據(jù)訪問,O/R映射即將領(lǐng)域模型類和數(shù)據(jù)庫的表進(jìn)行映射,通過程序操作對(duì)象而實(shí)現(xiàn)表數(shù)據(jù)操作的能力,讓數(shù)據(jù)訪問操作無須關(guān)注數(shù)據(jù)庫相關(guān)的技術(shù)2022-08-08JAVA面試題 從源碼角度分析StringBuffer和StringBuilder的區(qū)別
這篇文章主要介紹了JAVA面試題 從源碼角度分析StringBuffer和StringBuilder的區(qū)別,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,下面我們來一起學(xué)習(xí)下吧2019-07-07Java經(jīng)典面試題匯總:網(wǎng)絡(luò)編程
本篇總結(jié)的是Java 網(wǎng)絡(luò)編程相關(guān)的面試題,后續(xù)會(huì)持續(xù)更新,希望我的分享可以幫助到正在備戰(zhàn)面試的實(shí)習(xí)生或者已經(jīng)工作的同行,如果發(fā)現(xiàn)錯(cuò)誤還望大家多多包涵,不吝賜教,謝謝2021-07-07如何將maven項(xiàng)目導(dǎo)出jar包(最簡單方法)
大家都知道對(duì)于將maven項(xiàng)目導(dǎo)出jar包有好幾種方式,本文給大家分享一種方式最容易且最方便,感興趣的朋友跟隨小編一起看看吧2023-11-11