GreenDao 공식 자습서 확장판(2)
지난번에 그린다이아 생성 프로젝트 다이오의 내용을 제공했는데 이번에는 주로 다이오의 인용으로 다이오가 조작하는 것을 잘 아는 어린이 신발은 스스로 생략할 수 있다.
1. 의존 추가
두 가지 방법
1. Android Studio에서 Maven Central 검색을 사용하여 추가:
[Project Structure] --> [Your Module Name] --> [Dependencies] --> [Library Dependencies]가 Maven Central 검색 상자에서 검색
greenDao
하고 선택de.greenrobot:greendao:2.1.0
합니다.2.build을 직접 수정합니다.gradle
구체적인 절차는 앞의 문장을 참고하시오
2. 생성된 Dao 클래스 호출
공식 Example 참조
final DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
String comment = "Added on " + df.format(new Date());
Note note = new Note(null, noteText, comment, new Date());
noteDao.insert(note);//
Log.d("DaoExample", "Inserted new note, ID: " + note.getId());
cursor.requery();
}
insert
외에update
,delete
방법이 제공되고, 조회는 getWritableDatabase()
로 대상 조작을 획득한다.DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "notes-db", null); SQLiteDatabase noteDb = helper.getWritableDatabase(); Cursor cursor = noteDb.query(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy);//query 구문은 스스로 Google or Baidu3. 마지막 건의는 구조의 느슨한 결합을 감안하여 가능한 한 자신의 클래스로 이런Dao류를 봉인하는 것을 권장한다. 그렇지 않으면 후기 유지보수가 매우 어려울 수 있다.
참조:
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.