【问题标题】:Hibernate Query filter by Regex expression通过正则表达式进行休眠查询过滤器
【发布时间】:2015-12-25 19:06:03
【问题描述】:

我有一个实体,它有一个模式列。根据与给定字符串匹配的模式来查找现有记录的最佳方法是什么?

例如:

表格记录

| ID | pattern |
| 1  | /actions/{action-id:\d+}/{type-id:\d+}/{edge:[a-z][\w]+}/draft |,
| 2  | /actions/{action-id:\d+}/{edge:[a-z][\w]+}/submit |,
| 3  | /actions/{action-id:\d+}/{type-id:\d+}/{edge:[a-z][\w]+}/request |,
| 4  | /actions/{action-id:\d+}/{edge:[a-z][\w]+}/request |,
| 5  | /actions/{action-id:\d+}/{edge:[a-z][\w]+}/terminate |

输入字符串

/actions/1/send/request

这将返回带有ID = 4Action 记录,因为模式/actions/{action-id:\d+}/{edge:[a-z][\w]+}/request 与输入字符串匹配。

实现这一目标的最佳方式是什么?

注意:保证输入的字符串只匹配一个 表格中的图案

.

谢谢。

【问题讨论】:

    标签: java mysql regex hibernate hql


    【解决方案1】:

    你可以像这样添加 SQL 限制

    Criteria criteria ...
    
    criteria.add(Restrictions.sqlRestriction(theInputString+" REGEXP pattern")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-05
      • 1970-01-01
      • 2017-08-21
      • 1970-01-01
      • 1970-01-01
      • 2015-03-21
      相关资源
      最近更新 更多