1. 程式人生 > 程式設計 >Spring Data Jpa 中原生查詢 REGEXP 的使用詳解

Spring Data Jpa 中原生查詢 REGEXP 的使用詳解

目錄
  • Spring Data Jpa原生查詢 REGEXP 的使用
  • spring data jpa 原生查詢(查一個on中的某一欄位)

Spring Data Jpa原生查詢fhjNXswL REGEXP 的使用

REGEXP 與like 有通用之處, 單 regexp 有更好的精確度,更加自由靈活

http://www.cppcns.comjpa 中使用時 :其中 定位符 ^ 在jpa @query 註解中使用時需要加上引用號 e.g

@Query(value = "select p.id as id  from zt_products AS p 
       where 
        p.enabled=true 
       and fhjNXswL
p.name regexp '^'+?1+'$' ",nativeQuery = true) List<Map> findByName(String names);

如此 方可使用,,但是% 可以不用加。。。。

嗯 暫時就這個樣子///

後記:

在實際使用時 發現上述方法存在缺陷; 無論names傳的什麼值 查詢結果一樣;

@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/curhttp://www.cppcns.comrent/reference/html/#jpa.stored-procedures

spring data jpa 原生查詢(查一個json中的某一欄位)

SpringDataJpa中原生查詢REGEXP的使用詳解

jpa 查詢 :

@Component("ediHistoryDAO")
public interface EdiHistoryDAO extends CrudRepository<EdiHistoryDO,Integer>{
    EdiHistoryDO findById(BigInteger id);
    EdiHistoryDO findByEdiInfoId(BigInteger id);
    List<EdiHistoryDO> f
indByIdIn(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); }

SpringDataJpa中原生查詢REGEXP的使用詳解

以上為個人經驗,希望能給大家一個參考,也希望大家多多支援我們。