OrmLite简介

文档目录

 Android Examples    下载地址

pdf版本文档 http://ormlite.com/docs/ormlite.pdf

使用步骤

  1. 创建一个要保存到数据库的Java对象(使用注解标记), 查看Configuring a Class

             Setting Up Your Classes

@DatabaseTable(tableName = "accounts")
public class Account {

   @DatabaseField(id = true)
   private String name;

   @DatabaseField(canBeNull = false)
private String password; … }
@DatabaseField不指定列名, 默认就是类中字段的名称。

 @DatabaseField 注解 id含义

The @DatabaseField annotation can have the following fields:

columnName

String name of the column in the database that will hold this field. If not set then the field name, with normalized case, is used instead.

dataType

The type of the field as the DataType class. Usually the type is taken from Java class of the field and does not need to be specified. This corresponds to the SQL type. See section Persisted Data Types.

defaultValue

String default value of the field when we are creating a new row in the table. Default is none.

width

Integer width of the field – mostly used for string fields. Default is 0 which means to take the data-type and database-specific default. For strings that means 255 characters although some databases do not support this.

canBeNull

Boolean whether the field can be assigned to null value. Default is true. If set to false then you must provide a value for this field on every object inserted into the database.

id

Boolean whether the field is the id field or not. Default is false. Only one field can have this set in a class. Id fields uniquely identity a row and are required if you want to use the query, update, refresh, and delete by ID methods. Only one of this, generatedId, and generatedIdSequence can be specified. See section Fields With id.

·······

  2.  创建表,Dao

The @ForeignCollectionField annotation supports the following fields:

原文地址:https://www.cnblogs.com/huyang011/p/7641648.html