java实现mongodb的模糊查询

public Result<List<Code>> getCodes(@RequestParam(required = false) String name, @RequestHeader(required = false) HttpHeaders headers)
{

Query query = new Query();

Criteria criteria = new Criteria();
name = name.trim();
if(name.equals("") || name.equals(null)){
criteria.and("name").is(name);
}else{
Criteria name= new Criteria();
name.and("name").regex("^.*" +name+ ".*$");
Criteria value= new Criteria();
value.and("value").regex("^.*" +name+ ".*$");

criteria.orOperator(name,value);//查询条件or
}

query.addCriteria(criteria);

//根据name和code进行模糊查询
//db.getCollection(‘code‘).find({"$or":[{"code" : /GM/},{"value":/感冒/}]})
List<Code> codes = mongoTemplate.find(query,Code.class, "code");

return new Result<List<Code>>("0", "查询成功", codes );
}

java实现mongodb的模糊查询

上一篇:sqlmap从入门到精通-第七章-7-6 绕过WAF脚本-commalessmid.py&commentbeforeparentheses.py


下一篇:MySql隔离级别:RU / RC / RR / S + 脏读 / 不可重复读 / 幻读 / 可重复读