Spring Data Jpa 中原生查詢 REGEXP 的使用詳解
阿新 • • 發佈:2021-12-09
目錄
- 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 fhjNXswLp.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中的某一欄位)
:
jpa 查詢 :
@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); }
以上為個人經驗,希望能給大家一個參考,也希望大家多多支援我們。