android:kotlin语言使用greendao3,这原因我服了

本文详细介绍了如何在Android项目中使用Kotlin配合GreenDAO3进行数据库操作,包括添加Gradle配置、创建实体类、自动生成 Dao 类、数据库管理类的构建以及数据的增删改查操作。
摘要由CSDN通过智能技术生成

这里写图片描述

步骤一、在自己的build.gradle中加入这些配置


  • 在app的build.gradle中

apply plugin: ‘org.greenrobot.greendao’

greendao {

//数据库的schema版本,也可以理解为数据库版本号

schemaVersion 1

//设置DaoMaster、DaoSession、Dao包名,也就是要放置这些类的包的全路径。

daoPackage ‘tsou.com.simple.greendaoforkotlin.greendao’

//设置DaoMaster、DaoSession、Dao目录

targetGenDir ‘src/main/java’

}

dependencies

compile ‘org.greenrobot:greendao:3.2.0’

}

  • 在项目的build.gradle中

buildscript {

ext.kotlin_version = ‘1.1.50’

repositories {

mavenCentral()

google()

jcenter()

}

dependencies {

classpath ‘com.android.tools.build:gradle:3.0.0-beta7’

classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version”

classpath ‘org.greenrobot:greendao-gradle-plugin:3.2.0’

// NOTE: Do not place your application dependencies here; they belong

// in the individual module build.gradle files

}

}

步骤二、创建Student实体类


package tsou.com.simple.greendaoforkotlin.bean;

import android.support.annotation.Keep;

import org.greenrobot.greendao.annotation.Entity;

import org.greenrobot.greendao.annotation.Id;

import org.greenrobot.greendao.annotation.Generated;

@Entity(generateConstructors = false)

public class Student {

@Id

private Long id;

private String name;

private int age;

public Student() {

}

@Keep

public Student(String name, int age) {

this.name = name;

this.age = age;

}

public Student(Long id, String name, int age) {

this.id = id;

this.name = name;

this.age = age;

}

@Keep

public Long getId() {

return id;

}

@Keep

public void se

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值