Mongodb的核心数据操作MongodbBaseDao

public abstract class MongodbBaseDao {

Logger log = Logger.getLogger(this.getClass()); // spring mongodb 集成操作类
                                                // protected MongoTemplate
                                                // mongoTemplate; //
                                                // 链接本地数据库并创建数据表

public void CreateCollection(String collectionName) {
    try {
        log.info("Collection created successfully");
    } catch (Exception e) {
        System.err.println(e.getClass().getName() + ": " + e.getMessage());
    }
} // 获取数据表 public DBCollection GetCollection(String collectionName) {
    // DBCollection coll = null; try { coll =
    // mongoTemplate.getCollection(collectionName); return coll; } catch
    // (Exception e) { System.err.println(e.getClass().getName() + ": " +
    // e.getMessage()); } return coll; } // 通过条件查询实体(集合) public List<T>
    // Listfind(Query query) { return mongoTemplate.find(query,
    // this.getEntityClass()); } // 通过一定的条件查询一个实体 public T findOne(Query
    // query) { return (T) mongoTemplate.findOne(query,
    // this.getEntityClass()); } // 通过条件查询更新数据 public void update(Query
    // query, Update update) { mongoTemplate.upsert(query, update,
    // this.getEntityClass()); } // 保存一个对象到mongodb public T save(T bean) {
    // mongoTemplate.save(bean); return bean; } // 通过ID获取记录 public T
    // get(String id) { return (T) mongoTemplate.findById(id,
    // this.getEntityClass()); } // 通过ID获取记录,并且指定了集合名 public T get(String
    // id, String collectionName) { return (T) mongoTemplate.findById(id,
    // this.getEntityClass(), collectionName); } // 获取需要操作的实体类class
    // protected abstract Class getEntityClass(); //
    // spring容器注入mongodbTemplate protected abstract void
    // setMongoTemplate(MongoTemplate mongoTemplate);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值