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 );
}