当前位置:网站首页>mongo模糊查詢,帶有特殊字符需要轉義,再去查詢
mongo模糊查詢,帶有特殊字符需要轉義,再去查詢
2022-06-22 04:34:00 【12程序猿】
mongdb 模糊查詢,要檢索的內容中還有特殊符號,造成 檢索不出來數據,想要實現檢測效果,需要對 檢測內容中的特殊字符進行轉義,才能達到檢索效果
一、轉義正則特殊字符 方法
/** * 轉義正則特殊字符 ($()*+.[]?\^{},|) * * @param keyword * @return */
public static String escapeExprSpecialWord(String keyword) {
String[] fbsArr = {
"\\", "$", "(", ")", "*", "+", ".", "[", "]", "?", "^", "{", "}", "|" };
for (String key : fbsArr) {
if (keyword.contains(key)) {
keyword = keyword.replace(key, "\\" + key);
}
}
return keyword;
}
二、應用
Criteria criteria = new Criteria();
//項目名稱
if (!ObjectUtils.isEmpty(mixingStationProductionRequesJson.getFgcmc())) {
// criteria.and("fgcmc").regex(".*?" + mixingStationProductionRequesJson.getFgcmc() + ".*?");
//項目名稱中帶(),造成檢測不出來 將括號用反斜杠"\"進行轉義 \(
String name=escapeExprSpecialWord(mixingStationProductionRequesJson.getFgcmc());
criteria.and("fgcmc").regex("^.*"+name+".*$");
}
Query query = Query.query(criteria);
List<MixingStationRealDataVo> list=mongoTemplate.find(query,MixingStationRealDataVo.class);
边栏推荐
- BFs of figure
- Fastadmin list multi image preview (zoom in preview, rotation) one line of code
- nest. Module dependency transitivity in JS practice
- Wechat applet uploading seven cattle cloud laravel
- What is a forum virtual host? How to choose?
- Use putty to configure port mapping to realize the access of the external network to the server
- Systematic arrangement | how many children's shoes have forgotten to be done carefully before the model development (practical operation)
- KS004 基于SSH通讯录系统设计与实现
- window10无法访问局域网共享文件夹
- Adjacency matrix, adjacency table, cross linked list, adjacency multi table
猜你喜欢

Low power radar sensing module, application of smart lock radar sensing scheme, smart radar sensor technology

Binary tree cueing

什么是论坛虚拟主机?如何挑选?

Idea blue screen solution

Spark - executor initialization &

Basic concept of graph

希尔排序

Huffman tree

Large website technology architecture | application server security defense

树莓派初步使用
随机推荐
kubernetes集群中工作节点Noready故障处理
Lightweight CNN design skills
Basic concept of graph
Learning signal integrity from scratch -- 7-si analysis and simulation
Large website technology architecture | application server security defense
Spark - Executor 初始化 && 报警都进行1次
PHP determines whether the current time has exceeded
Es cannot work, circuitbreakingexception
Fonctionnement de base du tableau de séquence
有了这几个刷题网站,还愁跳槽不涨薪?
Pourquoi golang ne recommande - t - il pas ceci / self / me / this / _ Ça.
Researcher of Shangtang intelligent medical team interprets organ image processing under intelligent medical treatment
ES无法工作,CircuitBreakingException
Search (intensive training)
KS004 基于SSH通讯录系统设计与实现
PCM data format
队列的顺序实现
IDEA安装及其使用详解教程
window10无法访问局域网共享文件夹
tinymce. Init() browser compatibility issue