gpt4 book ai didi

java - spring MongoRepository 查询正则表达式

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:53:07 26 4
gpt4 key购买 nike

我希望在查询注释中使用 MongoRepository 来使用正则表达式。到目前为止我找到的唯一信息是一个中文帖子,但没有解释它是如何工作的,我不确定是否是我要找的。

@Query("{ 'name':{'$regex':?2,'$options':'i'}, sales': {'$gte':?1,'$lte':?2 }}")public Page findByNameAndAgeRange(String name,double ageFrom,double ageTo,Pageable page);

有人知道是否可以在查询中使用特定的正则表达式吗?

问候。

最佳答案

i toggles case insensitivity, and allows all letters in the pattern to match upper and lower cases.

MongoDB docs 中阅读有关 $regex 的更多信息.

在您的查询中,您似乎混淆了参数顺序(名称正则表达式中的?2)。我认为应该是:

@Query("{ 'name':{$regex:?0,$options:'i'}, sales': {$gte:?1,$lte:?2}}") 
public Page findByNameAndAgeRange(String name,double ageFrom,double ageTo,Pageable page);

关于java - spring MongoRepository 查询正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16729728/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com