This article was last updated on 2024-01-18 15:11, 1,014 days ago. If content or image links are invalid, please leave feedback.
#Mongodb #临时
mongodb查询指定字段
@Test
public void fun1() {
DBObject fieldsObject = new BasicDBObject();
fieldsObject.put("_id", true);
fieldsObject.put("name", true);
fieldsObject.put("code", true);
fieldsObject.put("marketPrice", true);
BasicDBObject dbObject = new BasicDBObject();
fieldsObject.put("productId", "PD329321375342788608");
Query query = new BasicQuery(dbObject,fieldsObject);
List<Goods> goodsList = mongoTemplate.find(query, Goods.class);
String gson = new Gson().toJson(goodsList);
System.out.println(gson);
}
mongodb查询指定字段
http://localhost:8090/archives/1705561830629
Comments