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);
如此 方可使用,,但是% 可以不用加。。。。
嗯 暂时就这个样子///
后记:
在实际使用时 发现上述方法存在缺陷; 无论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/current/reference/html/#jpa.stored-procedures
spring data jpa 原生查询(查一个json中的某一字段)
数据库:
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); }
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
springboot多个service互相调用的事务处理方式
这篇文章主要介绍了springboot多个service互相调用的事务处理方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2022-02-02Spring Boot 整合持久层之Spring Data JPA
在介绍Spring Data JPA的时候,我们首先认识下Hibernate。Hibernate是数据访问解决技术的绝对霸主,使用O/R映射技术实现数据访问,O/R映射即将领域模型类和数据库的表进行映射,通过程序操作对象而实现表数据操作的能力,让数据访问操作无须关注数据库相关的技术2022-08-08JAVA面试题 从源码角度分析StringBuffer和StringBuilder的区别
这篇文章主要介绍了JAVA面试题 从源码角度分析StringBuffer和StringBuilder的区别,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,下面我们来一起学习下吧2019-07-07
最新评论