Android stadio litepal
2016-05-31 11:20
351 查看
今天看到技术交流群里有人招聘Android,要求会litepal.
我立马百度了下。嗯,我的学习技术的精神,是值得称赞的。
litepal就是操作数据库的一个框架。git地址:
https://github.com/LitePalFramework/LitePal/blob/master/README.md
使用很简单,readme都写好了。
1.配置
Android stadio gradle里面增加
compile ‘org.litepal.android:core:1.3.1’
2.清单文件配置
在application节点增加
android:name=”org.litepal.LitePalApplication”
3.在src main 下的assets 新建litepal.xml
里面格式:
4.写数据库的bean
5.在litepal里面写上
6.
7.增删改查自己看api吧。会Android原生的sqlite,学这个五分钟。
我立马百度了下。嗯,我的学习技术的精神,是值得称赞的。
litepal就是操作数据库的一个框架。git地址:
https://github.com/LitePalFramework/LitePal/blob/master/README.md
使用很简单,readme都写好了。
1.配置
Android stadio gradle里面增加
compile ‘org.litepal.android:core:1.3.1’
2.清单文件配置
在application节点增加
android:name=”org.litepal.LitePalApplication”
3.在src main 下的assets 新建litepal.xml
里面格式:
<litepal> <!-- Define the database name of your application. By default each database name should be end with .db. If you didn't name your database end with .db, LitePal would plus the suffix automaticly for you. For example: <dbname value="demo" ></dbname> --> <dbname value="demo" ></dbname> <!-- Define the version of your database. Each time you want to upgrade your database, the version tag would helps. Modify the models you defined in the mapping tag, and just make the version value plus one, the upgrade of database will be processed automaticly without concern. For example: <version value="1" ></version> --> <version value="1" ></version> <!-- Define your models in the list with mapping tag, LitePal will create tables for each mapping class. The supported fields defined in models will be mapped into columns. For example: <list> <mapping class="com.test.model.Reader"></mapping> <mapping class="com.test.model.Magazine"></mapping> </list> --> <list> <mapping class="cn.xinyu.com.myapplication.db.Student"></mapping> </list> </litepal>
4.写数据库的bean
public class Student extends DataSupport { private String name; private int age; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } }
5.在litepal里面写上
<mapping class="cn.xinyu.com.myapplication.db.Student"></mapping>
6.
//这句话就会生成所有litepal配置的表 SQLiteDatabase db = Connector.getDatabase();
7.增删改查自己看api吧。会Android原生的sqlite,学这个五分钟。
Student student=new Student(); student.setName("caoxinyu"); student.setAge(18); student.save(); List<Student> cursor=DataSupport.findAll(Student.class); System.out.println(cursor.size());
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories