• mongoTemplate query update (指定查询哪些字段)


    1.指定查询哪些字段

    方式一:

            Query query = new Query();
            query.fields().include("booking"); //包含该字段
            query.fields().exclude("salary");//不包含该字段
        Booking booking = mongoTemplate.findOne(query, Booking.class);
        @Test
        public void testName11() throws Exception {
            
                 Query query = Query.query(Criteria.where("bookingNo").is("UFL-BK2020070711530323920"));
                 Booking booking = new Booking();
                query.fields().include("bookingNo");
                query.fields().include("milestoneStatus");
                query.fields().include("bookingDateLoc");
    
                List<Booking> bookingList = mongoTemplate.find(query, Booking.class);
                System.err.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
                System.err.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
                System.err.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
                System.err.println(JSON.toJSONString(bookingList));

    方式2:

            QueryBuilder queryBuilder = new QueryBuilder(); 
            queryBuilder.or(new BasicDBObject("onumber", "002"), new BasicDBObject("cname","zcy1")); 
            BasicDBObject fieldsObject=new BasicDBObject();
            fieldsObject.put("onumber", 1);
            fieldsObject.put("cname", 1);
           Query query=new BasicQuery(queryBuilder.get(),fieldsObject)
    
  • 相关阅读:
    jQuery Ajax通用js封装
    java校验导入的模板
    一条sql查出数据库某张表的所有属性
    封装SpringJdbcTemplate
    ehCache 配置
    使用mybatis自动实现接口封装返回结果集
    js打开新窗口并且居中显示
    单例模式读取配置文件只创建一次
    递归
    函数声明,函数表达式
  • 原文地址:https://www.cnblogs.com/lshan/p/13280542.html
Copyright © 2020-2023  润新知