赞
踩
解析数据 添加到数据库实体类
class LoginActivityPresenter(val loginActivity: LoginActivity) : NetPresenter(){ override fun parserJson(json: String?) { val user = Gson().fromJson(json, UserBean::class.java) if(user != null){ val takeoutOpenHelper = TakeoutOpenHelper(loginActivity) val userdao : Dao<DBUser,Int> = takeoutOpenHelper.getDao(DBUser::class.java) val dbUser:DBUser = DBUser() dbUser.phone = user.data?.phone dbUser.pwd = user.data?.passwd userdao.create(dbUser) Log.e("#####login","缓存到数据库里面") loginActivity.onLoginSuccess() }else { loginActivity.onLoginFailed() }
数据库的实体类
@DatabaseTable(tableName = "t_user") class DBUser {
@DatabaseField(generatedId = true) var id:Int = 0
@DatabaseField(columnName = "pwd") var pwd:String ?= null
@DatabaseField(columnName = "phone") var phone:String ?= null
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。