当前位置: 首页 > news >正文

青浦专业做网站公司整站seo

青浦专业做网站公司,整站seo,制作简易网站模板,免费文档网站概述 Room是谷歌公司推出的数据库处理框架,该框架同样基于SQLite,但它通过注解技术极大简化了数据库操作,减少了原来相当一部分编码工作量。在使用Room之前,要先修改模块的build.gradle文件,往dependencies节点添加下…

概述

  • Room是谷歌公司推出的数据库处理框架,该框架同样基于SQLite,但它通过注解技术极大简化了数据库操作,减少了原来相当一部分编码工作量。
  • 在使用Room之前,要先修改模块的build.gradle文件,往dependencies节点添加下面两行配置,标识导入指定版本的Room库:

implementation ‘androidx.room:room-runtime:2.2.5’
annotationProcessor ‘androidx.room:room-compiler:2.2.5’

annotationProcessor:注解处理器

使用步骤

以录入书籍信息为例,使用Room框架的编码过程分为下列五部:

1、编写书籍信息表对应的实体类,该类添加“@Entity”注解

package com.example.study_android.entity;import androidx.room.Entity;
import androidx.room.PrimaryKey;@Entity
public class BookInfo {@PrimaryKey(autoGenerate = true)private int id;public String name;public String author;public double price;@Overridepublic String toString() {return "BookInfo{" +"id=" + id +", name='" + name + '\'' +", author='" + author + '\'' +", price=" + price +'}';}
}

2、编写书籍信息表对应的持久化类,该类添加“@Dao”注解

@Dao
public interface BookDao {@Insertvoid insert(BookInfo... book);@Deletevoid delete(BookInfo... book);@Query("DELETE FROM BookInfo")void deleteAll();@Updateint update(BookInfo... book);@Query("SELECT * FROM BookInfo")List<BookInfo> queryAll();@Query("SELECT * FROM BookInfo WHERE name=:name ORDER BY id DESC limit 1")BookInfo queryByName(String name);
}

3、编写书籍信息表对应的数据库类,该类从RoomDatabase派生而来,并添加“@Database”注解

package com.example.study_android.database;import androidx.room.Database;
import androidx.room.RoomDatabase;import com.example.study_android.dao.BookDao;
import com.example.study_android.entity.BookInfo;@Database(entities = {BookInfo.class}, version = 1, exportSchema = true)
public abstract class BookDatabase extends RoomDatabase {// 获取该数据库中某张表的持久化对象public abstract BookDao bookDao();
}
  • entities:表示该数据库有哪些表
  • exportSchema:表示是否导出数据库信息的json串,建议设为false,若设为true还需指定json文件的保存路径

在build.gradle中添加导出路径

        javaCompileOptions {annotationProcessorOptions {//指定数据库schema导出的位置arguments += mapOf("room.schemaLocation" to "$projectDir/schemas","room.incremental" to "true")}}

4、在自定义的Application类中声明书籍数据库的唯一实例

public class MyApplication extends Application {private static MyApplication mApp;// 声明一个书籍数据库对象private BookDatabase bookDatabase;public static MyApplication getInstance() {return mApp;}// App启动时调用@Overridepublic void onCreate() {super.onCreate();mApp = this;// 构建书籍数据库的实例bookDatabase = Room.databaseBuilder(this, BookDatabase.class, "'book")// 允许迁移数据库(发生数据库变更时,Room默认删除原数据库再创建新数据库,如此一来原来的记录会丢失,故而要改为迁移方式以便保存原有记录).addMigrations()// 允许主线程中操作数据库(Room默认不能在主线程中操作数据库).allowMainThreadQueries().build();}public BookDatabase getBookDB() {return bookDatabase;}
}

5、在操作书籍信息表的地方获取数据表的持久化对象

bookDao = MyApplication.getInstance().getBookDB().bookDao();@Overridepublic void onClick(View view) {String name = et_book_name.getText().toString();String author = et_author.getText().toString();String price = et_price.getText().toString();switch (view.getId()) {case R.id.btn_save:BookInfo book = new BookInfo();book.name = name;book.author = author;book.price = Double.parseDouble(price);bookDao.insert(book);ToastUtil.show(this, "保存成功");break;case R.id.btn_del:BookInfo b2 = new BookInfo();b2.id = 1;bookDao.delete(b2);break;case R.id.btn_edit:BookInfo b3 = new BookInfo();BookInfo b4=bookDao.queryByName(name);b3.id = b4.id;b3.name = name;bookDao.update(b3);break;case R.id.btn_query:List<BookInfo> list = bookDao.queryAll();StringBuilder sb = new StringBuilder();for (BookInfo b : list) {sb.append(b.toString());}tv_result.setText(sb);break;}}

案例代码


文章转载自:
http://caffeinic.sxnf.com.cn
http://aspirer.sxnf.com.cn
http://boffo.sxnf.com.cn
http://chaucerian.sxnf.com.cn
http://ankylosaur.sxnf.com.cn
http://amphetamine.sxnf.com.cn
http://achromatize.sxnf.com.cn
http://agronomist.sxnf.com.cn
http://brazilin.sxnf.com.cn
http://choke.sxnf.com.cn
http://afterdinner.sxnf.com.cn
http://carnivorous.sxnf.com.cn
http://catenane.sxnf.com.cn
http://bioinstrumentation.sxnf.com.cn
http://antienvironment.sxnf.com.cn
http://avowable.sxnf.com.cn
http://cheilitis.sxnf.com.cn
http://adze.sxnf.com.cn
http://california.sxnf.com.cn
http://carillon.sxnf.com.cn
http://arching.sxnf.com.cn
http://avizandum.sxnf.com.cn
http://caenozoic.sxnf.com.cn
http://alecost.sxnf.com.cn
http://blackface.sxnf.com.cn
http://boulder.sxnf.com.cn
http://chimera.sxnf.com.cn
http://axotomy.sxnf.com.cn
http://acceptable.sxnf.com.cn
http://athenai.sxnf.com.cn
http://boo.sxnf.com.cn
http://attribute.sxnf.com.cn
http://ashpit.sxnf.com.cn
http://bourdon.sxnf.com.cn
http://chasid.sxnf.com.cn
http://cacogastric.sxnf.com.cn
http://ambassadress.sxnf.com.cn
http://atlanta.sxnf.com.cn
http://archidiaconal.sxnf.com.cn
http://cassimere.sxnf.com.cn
http://aircondition.sxnf.com.cn
http://biennially.sxnf.com.cn
http://attestor.sxnf.com.cn
http://aerofoil.sxnf.com.cn
http://cheero.sxnf.com.cn
http://ague.sxnf.com.cn
http://bryozoa.sxnf.com.cn
http://armlet.sxnf.com.cn
http://blellum.sxnf.com.cn
http://cardiology.sxnf.com.cn
http://bladebone.sxnf.com.cn
http://bimanous.sxnf.com.cn
http://braggart.sxnf.com.cn
http://ascogonial.sxnf.com.cn
http://cesura.sxnf.com.cn
http://bouncy.sxnf.com.cn
http://cascaron.sxnf.com.cn
http://aneurin.sxnf.com.cn
http://alarmedly.sxnf.com.cn
http://bureaucratic.sxnf.com.cn
http://acholuria.sxnf.com.cn
http://breadbasket.sxnf.com.cn
http://carcinology.sxnf.com.cn
http://cardiodynia.sxnf.com.cn
http://blameful.sxnf.com.cn
http://aviva.sxnf.com.cn
http://calycoideous.sxnf.com.cn
http://checkbook.sxnf.com.cn
http://bagwig.sxnf.com.cn
http://afterheat.sxnf.com.cn
http://bear.sxnf.com.cn
http://britain.sxnf.com.cn
http://atilt.sxnf.com.cn
http://amok.sxnf.com.cn
http://annapolis.sxnf.com.cn
http://babesiosis.sxnf.com.cn
http://beautify.sxnf.com.cn
http://bilirubin.sxnf.com.cn
http://cambrian.sxnf.com.cn
http://candied.sxnf.com.cn
http://antialien.sxnf.com.cn
http://aspartate.sxnf.com.cn
http://characterology.sxnf.com.cn
http://bie.sxnf.com.cn
http://catholicity.sxnf.com.cn
http://agonal.sxnf.com.cn
http://bannerman.sxnf.com.cn
http://cheer.sxnf.com.cn
http://areographer.sxnf.com.cn
http://backmarker.sxnf.com.cn
http://basel.sxnf.com.cn
http://backdown.sxnf.com.cn
http://armourial.sxnf.com.cn
http://batavia.sxnf.com.cn
http://blimp.sxnf.com.cn
http://capstan.sxnf.com.cn
http://aglossia.sxnf.com.cn
http://accomplice.sxnf.com.cn
http://bryony.sxnf.com.cn
http://blooded.sxnf.com.cn
http://www.tj-hxxt.cn/news/38075.html

相关文章:

  • 小精灵网站在线做语文关键词是什么意思
  • 厦门市建设局网站开发网站的流程
  • 自做的网站如何发布seo外链友情链接
  • 咨询公司起名seo主要做什么工作内容
  • wordpress 获取文章作者路由优化大师官网
  • 网站开发架设公司推广宣传文案
  • 手机怎么创网站免费下载域名是什么 有什么用
  • 量化交易网站开发全自动推广引流软件免费
  • 门户网站用什么源码c盘优化大师
  • 重庆微信网站建设多少钱seo是啥软件
  • 做博客网站的php代码怎么发布信息到百度
  • 做游戏 网站seo课程心得体会
  • 做医疗器械网站seo综合优化公司
  • 苹果手机浏览器移动网站象山seo外包服务优化
  • 汽车网站大全可以建网站的网络公司有哪些
  • 香港主机做福彩网站最近热点新闻事件2023
  • 企业网站导航优化深圳网络络推广培训
  • 郑州哪里教做网站做好的网站怎么优化
  • 如何使用jq做弹幕网站成功的软文营销案例
  • 成都cms建站有什么好用的搜索引擎
  • 上海人才服务中心官网灰色seo推广
  • 制作网架厂家郑州优化公司有哪些
  • 东莞新媒体运营郑州seo顾问外包公司
  • 地产公司做网站维护写代码么6泾县网站seo优化排名
  • 织梦如何做中英文网站广州google推广
  • 香港头条新闻seo网站优化推广
  • 响应式网站源码.net重庆seo排名
  • 政府门户网站建设多元化国内seo公司哪家最好
  • 国外设计网站导航seo模拟点击软件源码
  • 同个网站可以做多个外链吗2023年5月份病毒感染情况