以Spring Redis数据上我需要的字符串开头的检索对象

问题描述 投票:0回答:1

我有具有此属性的Foo类

public class Foo {
 private String fooPath;
}

而且我正在使用,FooRepository扩展了CrudRepository,QueryByExampleExecutor

但是spring数据不支持字符串匹配器REGEX

Redis按示例查询不支持字符串匹配器REGEX。支持的匹配器为:[DEFAULT,EXACT]。

如何检索以所需字符串开头的所有Foo对象?

spring spring-data spring-data-redis
1个回答
0
投票

也许像这样吗?

@Repository
FooRepository extends CrudRepository, QueryByExampleExecutor {


    @Query("SELECT Foo f where f.fooPath REGEXP :myRegexp")
    public Foo findLikePath(@Param("myRegexp")  String myRegexp);

}


更新:看这篇文章

How to use Regex keyword in Spring Data Repository Method

© www.soinside.com 2019 - 2024. All rights reserved.