Spring?Data?Jpa?中原生查詢?REGEXP?的使用詳解
Spring Data Jpa原生查詢 REGEXP 的使用
REGEXP 與like 有通用之處, 單 regexp 有更好的精確度,更加自由靈活
在jpa 中使用時 :其中 定位符 ^ 在jpa @query 注解中使用時需要加上引用號 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);
如此 方可使用,,但是% 可以不用加。。。。
嗯 暫時就這個樣子///
后記:
在實際使用時 發(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 表達式 直接在這里和一起會不起作用
可參考:
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 原生查詢(查一個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); }
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
java連接mysql數(shù)據(jù)庫實現(xiàn)單條插入和批量插入
這篇文章主要為大家詳細介紹了java連接mysql數(shù)據(jù)庫實現(xiàn)單條插入和批量插入,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-08-08Java利用位運算實現(xiàn)比較兩個數(shù)的大小
這篇文章主要為大家介紹了,在Java中如何不用任何比較判斷符(>,==,<),返回兩個數(shù)( 32 位整數(shù))中較大的數(shù),感興趣的可以了解一下2022-08-08springboot多個service互相調(diào)用的事務(wù)處理方式
這篇文章主要介紹了springboot多個service互相調(diào)用的事務(wù)處理方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-02-02Spring?Boot?整合持久層之Spring Data JPA
在介紹Spring Data JPA的時候,我們首先認識下Hibernate。Hibernate是數(shù)據(jù)訪問解決技術(shù)的絕對霸主,使用O/R映射技術(shù)實現(xiàn)數(shù)據(jù)訪問,O/R映射即將領(lǐng)域模型類和數(shù)據(jù)庫的表進行映射,通過程序操作對象而實現(xiàn)表數(shù)據(jù)操作的能力,讓數(shù)據(jù)訪問操作無須關(guān)注數(shù)據(jù)庫相關(guān)的技術(shù)2022-08-08JAVA面試題 從源碼角度分析StringBuffer和StringBuilder的區(qū)別
這篇文章主要介紹了JAVA面試題 從源碼角度分析StringBuffer和StringBuilder的區(qū)別,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,下面我們來一起學(xué)習(xí)下吧2019-07-07Java經(jīng)典面試題匯總:網(wǎng)絡(luò)編程
本篇總結(jié)的是Java 網(wǎng)絡(luò)編程相關(guān)的面試題,后續(xù)會持續(xù)更新,希望我的分享可以幫助到正在備戰(zhàn)面試的實習(xí)生或者已經(jīng)工作的同行,如果發(fā)現(xiàn)錯誤還望大家多多包涵,不吝賜教,謝謝2021-07-07