-
build.gradle(:app)配置,添加:
apply plugin: 'org.greenrobot.greendao'
添加引用:
implementation 'org.greenrobot:greendao:3.3.0'
添加greedao配置:
greendao { schemaVersion 1 daoPackage 'com.test.dao' targetGenDir 'src/main/java' }
完整配置:
- build.gradle(:My Application)配置,添加:
buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:7.1.2' classpath 'org.greenrobot:greendao-gradle-plugin:3.3.0' } }
- 在项目中的实体类中添加@Entity注解:
@Entity public class TestUser { private Long userId; private String nickname; private String headIcon; }
- 重新构建一下项目第三步中的实体类变为:
同时会在com.text.dao包下生成DaoMaster,DaoSession,TestUserDao三个类@Entity public class TestUser { private Long userId; private String nickname; private String headIcon; @Generated(hash = 1965623583) public TestUser(Long userId, String nickname, String headIcon) { this.userId = userId; this.nickname = nickname; this.headIcon = headIcon; } @Generated(hash = 925009630) public TestUser() { } public Long getUserId() { return this.userId; } public void setUserId(Long userId) { this.userId = userId; } public String getNickname() { return this.nickname; } public void setNickname(String nickname) { this.nickname = nickname; } public String getHeadIcon() { return this.headIcon; } public void setHeadIcon(String headIcon) { this.headIcon = headIcon; } }
注意:本文归作者所有,未经作者允许,不得转载