mongoTemplate查询指定字段

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Booleaning/article/details/85156775

mongoTemplate查询指定字段

    @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);
    }
展开阅读全文

没有更多推荐了,返回首页