首页 > 移动平台 > 详细

Android常用开源库的使用——————————————LitePal的使用方法

时间:2018-11-22 13:01:50      阅读:171      评论:0      收藏:0      [点我收藏+]

LitePal是一款开源Android数据库框架,采用了对象关系映射的模式,

详细的使用文档见LitePal项目的Github主页

快速设置步骤:

1. Include library

Edit your build.gradle file and add below dependency.

If you program with Java:

dependencies {
    implementation ‘org.litepal.android:java:3.0.0‘
}

2. Configure litepal.xml

Create a file in the assets folder of your project and name it as litepal.xml. Then copy the following codes into it.

<?xml version="1.0" encoding="utf-8"?>
<litepal>
    <dbname value="demo" />

    <version value="1" />

    <list>
    </list>
    
</litepal>

This is the only configuration file, and the properties are simple.

  • dbname configure the database name of project.
  • version configure the version of database. Each time you want to upgrade database, plus the value here.
  • list configure the mapping classes.
  • storage configure where the database file should be stored. internal and external are the only valid options.

3. Configure LitePalApplication

You don‘t want to pass the Context param all the time. To makes the APIs simple, just configure the LitePalApplication in AndroidManifest.xml as below:

<manifest>
    <application
        android:name="org.litepal.LitePalApplication"
        ...
    >
        ...
    </application>
</manifest>

 

Android常用开源库的使用——————————————LitePal的使用方法

原文:https://www.cnblogs.com/kyun/p/10000326.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!