Android常用的room增删改查语句(外部数据库),赶紧收藏备战金三银四【附源码】_mb612648928888e

public String getWordclass() {      return wordclass;  }  public void setWordclass(String wordclass) {      this.wordclass = wordclass;  }  public String getWordtime() {      return wordtime;  }  public void setWordtime(String wordtime) {      this.wordtime = wordtime;  }  public Forget(String wordname, String wordclass, String wordtime) {      this.wordname = wordname;      this.wordclass = wordclass;      this.wordtime = wordtime;  }

}

 **Dao文件如下:** 

@Dao //访问数据库的一个接口

public interface WordDao {

@Insert  void insertWords(Forget... forgets);  //根据单词名称删除表中数据  @Query("DELETE  FROM FORGET where wordname=:name")  void  deleteWords(String name);  //根据单词名称更新表中数据  @Query("UPDATE FORGET SET wordclass= :wordclasss WHERE wordname = :wordname")  void  updateWords(String wordname,String wordclasss);  //查询表中某数据是否存在  @Query("select 1 from forget where wordname =:wordname  limit 1")  int forgetWordisExist(String wordname);  //分页加载:

@Query(" SELECT example,english,phonetic,chinese FROM FOURS limit :start,:end")

 LiveData<List<Word>> getHarfWordsLive(int start,int end);  //查询全部  @Query(" SELECT * FROM FORGET ORDER BY rowid DESC")  LiveData<List<Forget>> getAllForgetLive();  //根据字段查询  @Query("SELECT * FROM FORGET WHERE wordname= :name")  Forget getForgetByName(String name);

}

 **DataBase文件如下** 

@Database(entities = {Forget.class},version =1,exportSchema = false)

public abstract class WordDataBase extends RoomDatabase {

private static WordDataBase INSTANCE;  static synchronized WordDataBase getDatabase(final Context context){      if (INSTANCE==null){                  INSTANCE= Room.databaseBuilder(context.getApplicationContext(),WordDataBase.class,"word.db")                        .createFromAsset("word.db") //预填充数据库                        .fallbackToDestructiveMigration()                        .build();      }      return INSTANCE;  }  public abstract WordDao getWordDao();

}

 **Repository文件如下** 

class WordRepository {

private LiveData<List<Forget>> allForgetLive;  private WordDao wordDao;  private WordDataBase wordDatabase;  WordRepository(Context context){      //单例      wordDatabase=WordDataBase.getDatabase(context.getApplicationContext());      allForgetLive=wordDao.getAllForgetLive();  }  public LiveData<List<Forget>> getAllForgetLive() {      return allForgetLive;  }  public Forget getForgetByName(String name) {      return wordDao.getForgetByName(name);  }  public int forgetWordisExist(final String wordname){    return   wordDao.forgetWordisExist(wordname);  }  void insertWords(final Forget...forgets){      RxBusMax.getInstance().chainProcess(new Func1() {          @Override          public Object call(Object o) {              wordDao.insertWords(forgets);              return null;          }      });  }  void deleteWords(final String name){      RxBusMax.getInstance().chainProcess(new Func1() {          @Override          public Object call(Object o) {              wordDao.deleteWords(name);              return null;          }      });  }  void updateWords(final String wordname,final String wordclass){      RxBusMax.getInstance().chainProcess(new Func1() {          @Override          public Object call(Object o) {              wordDao.updateWords(wordname,wordclass);              return null;          }      });  }

}

  **ViewMode文件如下**  ### 文末  架构师不是天生的,是在项目中磨练起来的,所以,我们学了技术就需要结合项目进行实战训练,那么在Android里面最常用的架构无外乎 MVC,MVP,MVVM,但是这些思想如果和模块化,层次化,组件化混和在一起,那就不是一件那么简单的事了,我们需要一个真正身经百战的架构师才能讲解透彻其中蕴含的深理。  ![移动架构师](https://s2.51cto.com/images/20210921/1632208637701254.jpg)  ![系统学习技术大纲](https://s2.51cto.com/images/20210921/1632208637103267.jpg)  **一线互联网Android面试题总结含详解(初级到高级专题)**  ![image](https://s2.51cto.com/images/20210921/1632208638532618.jpg)  **[CodeChina开源项目:《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》](https://ali1024.coding.net/public/P7/Android/git)**

本站由小牛团队全力维护,小牛十年了,大家已经步入中年 。本站源码全部经过团队成员测试并调试,价格可能比其它网站略贵几元钱,不解释!
小牛资源 » Android常用的room增删改查语句(外部数据库),赶紧收藏备战金三银四【附源码】_mb612648928888e

发表评论

全站资源亲测可用,价格略高几元,不解释

立即查看 了解详情