赞
踩
数据库实体类
@DatabaseTable(tableName = "t_menu") class MenuDb { @DatabaseField(generatedId = true) val id:Int = 0 @DatabaseField(columnName = "menuname") var menuname:String ?= null @DatabaseField(columnName = "menunum") var menunum:String ?= null @DatabaseField(columnName = "pic") var pic:String ?= null @DatabaseField(columnName = "shapname") var shapname:String ?= null @DatabaseField(columnName = "address") var address:String ?= null // @DatabaseField(columnName = "sum") var sum:Int = 0 }
OpenHolder类
class MenuOpenHelper(context: Context?) : OrmLiteSqliteOpenHelper(context,"menu.db",null,1) { override fun onCreate(database: SQLiteDatabase?, connectionSource: ConnectionSource?) { //创建user表 TableUtils.createTable(connectionSource,MenuDb::class.java) } override fun onUpgrade( db: SQLiteDatabase?, connectionSource: ConnectionSource?, oldVersion: Int, newVersion: Int ) { } }
添加数据库
val menuOpenHelper =MenuOpenHelper(this)
dao = menuOpenHelper.getDao(MenuDb::class.java)
val menuDb:MenuDb = MenuDb()
menuDb.menuname = menuname
menuDb.pic = pic
menuDb.menunum = num.toString()
menuDb.shapname = shapname
menuDb.address = address
menuDb.sum = 1
dao.create(menuDb)
Toast.makeText(this@MeauActivity,"加入成功",Toast.LENGTH_SHORT).show()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。