Giải pháp chuyển đổi số trọn gói cho doanh nghiệp Việt

Tạo file Object car - Ví lập trình android quản lý car

Ví lập trình android quản lý car

← Toàn bộ tài liệu


Bước 2: Tạo file Object car

Bài 2/36 Xem dạng sách

Tên FIle: Car.java

Nơi lưu file: java/com/vantinviet/adayroionline/viewobject

Nội dung file:
package com.vantinviet.adayroionline.viewobject;

import androidx.annotation.NonNull;
import androidx.room.Embedded;
import androidx.room.Entity;

import com.google.gson.annotations.SerializedName;

@Entity(primaryKeys = "id")// đối với mỗi đối tượng sẽ phải có khóa chính thường thì id là khóa chính
public class Car {

@NonNull
@SerializedName("_id")
public String id="";

@SerializedName("car_name") // lấy key theo api trả về
public String carName="";
@SerializedName("car_model")
public String carModel="";
@SerializedName("car_color")
public String carColor="";
@Embedded
@SerializedName("default_photo")
public Image defaultPhoto;
@SerializedName("description") // lấy key theo api trả về
public String carDescription="";
@SerializedName("added_date")
public String addedDate="";

//thêm nhiều thuộc tính nữa ở đây, nhớ thêm cả ở phương thức khởi tạo nữa nhé
//Phương thức khởi tạo
public Car() {

}
public Car(@NonNull String id, String carName,String carModel, String carColor,String carDescription, String added_date) {
this.id = id!=null?id:this.id;
this.carName=carName!=null?carName:this.carName;
this.carModel=carModel!=null?carModel:this.carModel;
this.carColor=carColor!=null?carColor:this.carColor;
this.carDescription= carDescription!=null?carDescription:this.carDescription;
this.addedDate=added_date!=null?added_date:this.addedDate;


}

@Override
public String toString() {
return "Car{" +
"id='" + id + '\'' +
", carName='" + carName + '\'' +
", carModel='" + carModel + '\'' +
", carColor='" + carColor + '\'' +
", defaultPhoto=" + defaultPhoto +
", carDescription='" + carDescription + '\'' +
", addedDate='" + addedDate + '\'' +
'}';
}
}

Sơ đồ quan hệ các bảng

Table Name: {{table.name}}
Num Name Type
{{field_index+1}}
{{field.name}} {{field.type}}

Hỏi đáp

Gửi với tên {{comment_full_name}}

Chưa có câu hỏi nào cho bài này.

Zalo 0936.006.058 Hotline 0936.006.058