内容简介:mongoHelper 是基于 spring-data-mongodb 的增强工具包,简化 CRUD 操作,提供类 jpa 的数据库操作。 传统关系型数据库及围绕它们构建的 orm 在项目开发中有很多难用的痛点,而 mongodb 这种文档性数据库的出现,...
mongoHelper 是基于 spring-data-mongodb 的增强 工具 包,简化 CRUD 操作,提供类 jpa 的数据库操作。
传统关系型数据库及围绕它们构建的 orm 在项目开发中有很多难用的痛点,而 mongodb 这种文档性数据库的出现,完美的解决了 sql 数据库在项目开发中的诸多痛点,在 mongodb4.0 以后支持了事务,已经可以完美的用于工程项目。spring-data-mongodb 已经对 mongodb 的操作做了一部分封装,但依然不够用,Query 与 Criteria 的操作依然有比较大的局限性,而且对于习惯 sql 操作和 sql orm 的人来说,其使用法则依然稍显别扭。mongoHelper 对 spring-data-mongodb 又进行了进一步封装,补充了 mysql 有但 mongodb 没有的特性,比如字段默认值,使其更易于使用,更接近与关系型数据库 orm 库,并添加了很多易于项目管理的功能。
使用mongoHelper之后, 能够进行类似与大多数mysql orm一样的查询分页语句封装
public Page search(Page page, String word, Integer type) {
CriteriaAndWrapper criteriaAndWrapper = new CriteriaAndWrapper();
if (StrUtil.isNotEmpty(word)) {
criteriaAndWrapper.and(new CriteriaOrWrapper().like(User::getName, word).like(User::getPhone, word));
}
if (type != null) {
criteriaAndWrapper.eq(User::getType, type);
}
page = mongoHelper.findPage(criteriaAndWrapper, new SortBuilder(User::getCreatTime, Direction.DESC), page, User.class);
return page;
}
单表操作语句也变得简单
- 按id删除:mongoHelper.deleteById(String, Class<?>)
- 按条件删除:mongoHelper.deleteByQuery(Criteria, Class<?>)
- 查询所有:mongoHelper.findAll(Class)
- 查询数量:mongoHelper.findCount(Class<?>)
- 根据id查询:mongoHelper.findById(String, Class)
- 根据条件查询:mongoHelper.findListByQuery(Criteria, Class<?>)
- 根据条件查询并分页:mongoHelper.findPage(Criteria, Page, Class<?>)
- 插入:mongoHelper.insert(Object)
- 插入或更新:mongoHelper.insertOrUpdate(Object)
- 根据id更新:mongoHelper.updateById(Object)
- 根据id更新全部字段:mongoHelper.updateAllColumnById(Object)
- 根据条件更新第一项:mongoHelper.updateFirst(Criteria, Update, Class<?>)
- 根据条件更新所有项:mongoHelper.updateMulti(Criteria, Update, Class<?>)
对查询语句的打印也格式化规范化, 可直接放到数据库客户端执行
db.admin.find({
"$and": [
{
"name": {
"$regex": "^.*ad.*$",
"$options": "i"
}
}
]
}).projection({
"name": 1
}).sort({
"id": -1
});
本次更新内容
1.添加使用Lambda获取字段名的方法
2.增加对springBoot 2.3.0的支持
3.修复一些bug
代码地址: https://gitee.com/cym1102/mongoHelper
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- Facebook开源增强版LASER库,包含93种语言工具包
- mybatis-plus 3.0.6 发布,Mybatis 增强工具包
- mybatis-plus 3.0.6 发布,Mybatis 增强工具包
- mongoHelper 0.2.5 发布,spring-data-mongodb 增强工具包
- mongoHelper 0.2.7 发布,spring-data-mongodb 增强工具包
- mongoHelper 0.1.6 发布,spring-data-mongodb 增强工具包
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Mathematica Cookbook
Sal Mangano / O'Reilly Media / 2009 / GBP 51.99
As the leading software application for symbolic mathematics, Mathematica is standard in many environments that rely on math, such as science, engineering, financial analysis, software development, an......一起来看看 《Mathematica Cookbook》 这本书的介绍吧!