xUtils3.0中DbUtils的使用
来源:互联网 发布:倚天现货指标公式源码 编辑:程序博客网 时间:2024/05/16 04:27
xUtils3框架地址
权限授予:
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
在项目中对于数据库的操作总体上来说,还是比较频繁的,所以我个人采用的是单例模式,将构建部分放在Application中,或者说是单独为此建立一个Application.
个人项目中的例子:CrediteApplication.java:
public class CreditApplication extends Application { public static Calendar TODAY; private static final String TAG = CreditApplication.class.getSimpleName(); private static Context mApplicationContext; private static DbManager.DaoConfig daoConfig; public static Activity currentAcivity; @Override public void onCreate() { mApplicationContext = this; SDKInitializer.initialize(this); x.Ext.init(this); x.Ext.setDebug(BuildConfig.DEBUG); // 是否输出debug日志, 开启debug会影响性能. TODAY = Calendar.getInstance(Locale.CHINA); daoConfig = new DbManager.DaoConfig()// .setDbName("credit.db") // 不设置dbDir时, 默认存储在app的私有目录.// .setDbDir(new File("/sdcard")) // "sdcard"的写法并非最佳实践, 这里为了简单, 先这样写了. .setDbVersion(2) .setDbOpenListener(new DbManager.DbOpenListener() { @Override public void onDbOpened(DbManager db) { // 开启WAL, 对写入加速提升巨大 db.getDatabase().enableWriteAheadLogging(); } }) .setTableCreateListener(new DbManager.TableCreateListener() { @Override public void onTableCreated(DbManager db, TableEntity<?> table) { Log.d(TAG,"onTableCreated: "+ table.toString()); } }) .setDbUpgradeListener(new DbManager.DbUpgradeListener() { @Override public void onUpgrade(DbManager db, int oldVersion, int newVersion) { // TODO: ... // db.addColumn(...); // db.dropTable(...); // ... // or // db.dropDb(); } });// try {// x.getDb(daoConfig).dropTable(SurInfo.class);// } catch (DbException e) {// e.printStackTrace();// } } public static DbManager getDbManager(){ return x.getDb(daoConfig); } // 获取ApplicationContext public static Context getContext() { return mApplicationContext; }}
CreditApplication.getDbManager()
SurInfoField surInfoField = CreditApplication.getDbManager().selector(SurInfoField.class)
.where("fieldId","=",fieldId).findFirst();
WhereBuilder builder = WhereBuilder.b("templateId", "in", integerList);
List<TemplateList> list = CreditApplication.getDbManager().selector(TemplateList.class)
.where(builder).findAll();
添加操作:
CreditApplication.getDbManager().saveOrUpdate(updateFileFieldList);
删除操作:
CreditApplication .getDbManager().deleteById(FileField.class,deleteFileFieldList);
Gradle配置:
compile 'org.xutils:xutils:3.3.38'
1 0
- xUtils3.0中DbUtils的使用
- xUtils3中ImageOptions的使用
- XUtils3.0的简单使用
- xUtils中DbUtils的使用
- xutils3.0 的使用及demo
- xUtils3.0的基本使用规则
- xutils3.0下载器的使用
- Xutils3的使用
- xutils3的使用
- xUtils3的使用
- Xutils3的使用
- Xutils3的使用
- xUtils3的使用
- xUtils3数据库的使用
- xUtils3的使用
- Xutils3的基本使用
- Xutils3的使用
- xUtils3的简单使用
- IOUtils, FileUtils,FilenameUtils ,FileSystemUtils ,EndianUtils
- 让GDB支持STL的标准库的方法
- 通向架构师的道路(第三天)之apache性能调优
- 解决Maven提示:Could not read settings.xml
- Notification基础详解一(系统基础通知)
- xUtils3.0中DbUtils的使用
- LintCode : 比较字符串
- 从尾到头打印链表
- 什么是对象?什么是面向对象程序设计?面向对象语言有什么优点?
- ztree的数据绑定
- ListView多级联动
- 完全跨域的单点登录
- oracle中的||替换成mysql的concat_ws('',
- iOS动画篇:核心动画