DBObject dbObject = new BasicDBObject();
//dbObject.put("name", "zhangsan"); //查询条件
BasicDBObject fieldsObject=new BasicDBObject();
//指定返回的字段
fieldsObject.put("name", true);
fieldsObject.put("age", true);
fieldsObject.put("sex", true);
Query query = new BasicQuery(dbObject,fieldsObject);
List<Person> user = mongoTemplate.find(query, Person.class);
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/bigdata/9655.html