SpringData MongoDB模糊查询

一、不区分大小写

//完全匹配
Pattern pattern = Pattern.compile("^张$", Pattern.CASE_INSENSITIVE);
//右匹配
Pattern pattern = Pattern.compile("^.*$", Pattern.CASE_INSENSITIVE);
//左匹配
Pattern pattern = Pattern.compile("^张.*$", Pattern.CASE_INSENSITIVE);
//模糊匹配
Pattern pattern = Pattern.compile("^.*张.*$", Pattern.CASE_INSENSITIVE);
Query query = Query.query(Criteria.where(fieldName).regex(pattern));  
        List users = mongoTemplate.find(query, SimpleUserInfo.class, classname);
        return users;


你可能感兴趣的:(MongoDB)