首先spring自帶了mongodb的orm,spring data mongodb,但是這個框架非常難用,最令人抓狂的是每個文檔都要帶一個 _class 字段,因為這個是string的,所以占用不少空間,而且去除也比較麻煩。故而使用 zfoo orm 框架
基于MongoDB的orm框架,提供POJO對象和MongoDB數(shù)據(jù)庫之間的映射
1. IAccessor接口,為數(shù)據(jù)訪問接口
OrmContext.getAccessor().insert(obj)
OrmContext.getAccessor().delete(obj);
OrmContext.getAccessor().update(obj);
2. IQuery接口,為數(shù)據(jù)復(fù)雜查詢接口
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 IEntityLong> { }
test下中包含了所有增刪改查的教程,運(yùn)行之前請先安裝MongoDB
以上就是MongoDB orm框架的注意事項及簡單使用的詳細(xì)內(nèi)容,更多關(guān)于MongoDB orm框架的資料請關(guān)注腳本之家其它相關(guān)文章!
標(biāo)簽:黃石 池州 安順 呼倫貝爾 菏澤 楚雄 白山 舟山
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《MongoDB orm框架的注意事項及簡單使用》,本文關(guān)鍵詞 MongoDB,orm,框架,的,注意事項,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。