Simple use of ORM framework

6380 단어
First configure the information in the application in the configuration list

<meta-data
    android:name="AA_DB_NAME"
    android:value="date.db"/>
<meta-data
    android:name="AA_DB_VERSION"
    android:value="1"/>



Instantiate in a custom application

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        ActiveAndroid.initialize(this);
    }
}


Create a class that inherits Model, which is a table

  // 
@Table(name = "Items")
public class Item extends Model {
    //  
    @Column(name = "Name")
    public String name ;
    @Column(name = "Age")
    public Integer age;
    public Item(){
        super();
    }
    public Item(String name ,int age){
        this.name = name ;
        this.age = age ;
    }
}



code in activity




 Item item = new Item();
 
 // ( )
 item.name = " ";
 item.age = 25 ;
 item.save();

 /*// 
 Item items = item.load(Item.class,1);
 item.delete();

 new Delete().from(Item.class).where("Name=?","LiLei").execute();*/

 // , list :executeSingle()execute() 
List<Item> list =  new Select().from(Item.class).where("Name=?", " ").orderBy("Name ASC").execute();

 tv.setText(list.get(0).name+"-"+list.get(0).age+"   "+list.get(1).getId());

좋은 웹페이지 즐겨찾기