目录Ⅰ. 简介 Ⅱ. 注意事项 Ⅲ. 使用方法 Ⅳ. 教程 首先spring自带了mongoDB的ORM,spring data monGodb,但是这个框架非常难用,最令人抓狂的是
首先spring自带了mongoDB的ORM,spring data monGodb,但是这个框架非常难用,最令人抓狂的是每个文档都要带一个 _class 字段,因为这个是string的,所以占用不少空间,而且去除也比较麻烦。故而使用 zfoo orm 框架
基于MongoDB的orm框架,提供POJO对象和MongoDB数据库之间的映射
1. IAccessor接口,为数据访问接口
OrmContext.getAccessor().insert(obj)
OrmContext.getAccessor().delete(obj);
OrmContext.getAccessor().update(obj);
2. IQuery接口,为数据复杂查询接口
3. 缓存使用方法
例如有下列配置
<orm:config id="config" entity-package="com.zfoo.orm.**.entity">
<orm:host database="test" user="" passWord="">
<orm:address name="server0" url="127.0.0.1:27017"/>
</orm:host>
<!-- 缓存策略 -->
<orm:caches>
<orm:cache strategy="ten" size="10" expire-millisecond="600000"/>
<orm:cache strategy="hundred" size="100" expire-millisecond="600000"/>
<orm:cache strategy="thousand" size="1000" expire-millisecond="600000"/>
<orm:cache strategy="threeThousand" size="3000" expire-millisecond="600000"/>
<orm:cache strategy="tenThousand" size="10000" expire-millisecond="600000"/>
</orm:caches>
<!-- 持久化策略 -->
<orm:persisters>
<orm:persister strategy="cronDefault" type="cron" config="0,30 * * * * ?"/>
<orm:persister strategy="cron3s" type="cron" config="0/3 * * * * ?"/>
<orm:persister strategy="cron15s" type="cron" config="0/15 * * * * ?"/>
<orm:persister strategy="cron30s" type="cron" config="0/30 * * * * ?"/>
<orm:persister strategy="cron1m" type="cron" config="0 0/30 * * * ?"/>
<orm:persister strategy="time30s" type="time" config="30000"/>
</orm:persisters>
</orm:config>
有下列注解
@EntityCaches(cacheStrategy = "tenThousand", persister = @Persister("time30s"))
public class UserEntity implements IEntity<Long> {
}
test下中包含了所有增删改查的教程,运行之前请先安装MongoDB
以上就是MongoDB orm框架的注意事项及简单使用的详细内容,更多关于MongoDB orm框架的资料请关注编程网其它相关文章!
--结束END--
本文标题: MongoDB orm框架的注意事项及简单使用
本文链接: https://www.lsjlt.com/news/128580.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0